@md-code/follow-architecture 0.1.0 → 0.3.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 (436) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/LICENSE +202 -0
  3. package/README.md +597 -126
  4. package/dist/aliases.d.ts +3 -0
  5. package/dist/aliases.js +12 -0
  6. package/dist/args.d.ts +14 -0
  7. package/dist/args.js +77 -0
  8. package/dist/bin/follow-architecture.d.ts +2 -0
  9. package/dist/bin/follow-architecture.js +23 -0
  10. package/dist/code-roles/classify.d.ts +11 -0
  11. package/dist/code-roles/classify.js +43 -0
  12. package/dist/code-roles/connector.d.ts +5 -0
  13. package/dist/code-roles/connector.js +114 -0
  14. package/dist/code-roles/project.d.ts +12 -0
  15. package/dist/code-roles/project.js +122 -0
  16. package/dist/code-roles/roles.d.ts +8 -0
  17. package/dist/code-roles/roles.js +190 -0
  18. package/dist/config-options.d.ts +53 -0
  19. package/dist/config-options.js +35 -0
  20. package/dist/config-project.d.ts +4 -0
  21. package/dist/config-project.js +74 -0
  22. package/dist/config-report.d.ts +19 -0
  23. package/dist/config-report.js +134 -0
  24. package/dist/config-rule.d.ts +70 -0
  25. package/dist/config-rule.js +118 -0
  26. package/dist/config-state.d.ts +14 -0
  27. package/dist/config-state.js +96 -0
  28. package/dist/config.d.ts +82 -0
  29. package/dist/config.js +38 -0
  30. package/dist/css/index.d.ts +27 -0
  31. package/dist/css/index.js +140 -0
  32. package/dist/css/syntax/css/gate.d.ts +2 -0
  33. package/dist/css/syntax/css/gate.js +69 -0
  34. package/dist/css/syntax/css/index.d.ts +7 -0
  35. package/dist/css/syntax/css/index.js +41 -0
  36. package/dist/css/syntax/css/reference.d.ts +3 -0
  37. package/dist/css/syntax/css/reference.js +24 -0
  38. package/dist/css/syntax/language.d.ts +25 -0
  39. package/dist/css/syntax/language.js +69 -0
  40. package/dist/css/syntax/scss/index.d.ts +25 -0
  41. package/dist/css/syntax/scss/index.js +85 -0
  42. package/dist/css/syntax/scss/reference.d.ts +3 -0
  43. package/dist/css/syntax/scss/reference.js +11 -0
  44. package/dist/css/syntax/styled/document.d.ts +68 -0
  45. package/dist/css/syntax/styled/document.js +241 -0
  46. package/dist/css/syntax/styled/markup.d.ts +6 -0
  47. package/dist/css/syntax/styled/markup.js +76 -0
  48. package/dist/css/syntax/styled/template.d.ts +23 -0
  49. package/dist/css/syntax/styled/template.js +61 -0
  50. package/dist/css/syntax/tailwind/tailwind-engine.d.ts +23 -0
  51. package/dist/css/syntax/tailwind/tailwind-engine.js +37 -0
  52. package/dist/css/syntax/tailwind/tailwind.d.ts +26 -0
  53. package/dist/css/syntax/tailwind/tailwind.js +118 -0
  54. package/dist/css/value/check.d.ts +86 -0
  55. package/dist/css/value/check.js +122 -0
  56. package/dist/css/value/expression/arithmetic.d.ts +7 -0
  57. package/dist/css/value/expression/arithmetic.js +69 -0
  58. package/dist/css/value/expression/block.d.ts +9 -0
  59. package/dist/css/value/expression/block.js +91 -0
  60. package/dist/css/value/expression/conditional.d.ts +8 -0
  61. package/dist/css/value/expression/conditional.js +53 -0
  62. package/dist/css/value/expression/index.d.ts +5 -0
  63. package/dist/css/value/expression/index.js +69 -0
  64. package/dist/css/value/expression/map.d.ts +7 -0
  65. package/dist/css/value/expression/map.js +113 -0
  66. package/dist/css/value/object/index.d.ts +5 -0
  67. package/dist/css/value/object/index.js +103 -0
  68. package/dist/css/value/object/members.d.ts +7 -0
  69. package/dist/css/value/object/members.js +103 -0
  70. package/dist/css/value/object/node.d.ts +8 -0
  71. package/dist/css/value/object/node.js +129 -0
  72. package/dist/css/value/object/path.d.ts +10 -0
  73. package/dist/css/value/object/path.js +146 -0
  74. package/dist/css/value/pieces.d.ts +61 -0
  75. package/dist/css/value/pieces.js +55 -0
  76. package/dist/css/value/resolve.d.ts +33 -0
  77. package/dist/css/value/resolve.js +94 -0
  78. package/dist/css/value/scope.d.ts +27 -0
  79. package/dist/css/value/scope.js +187 -0
  80. package/dist/css/value/substitute.d.ts +10 -0
  81. package/dist/css/value/substitute.js +113 -0
  82. package/dist/css/value/values.d.ts +23 -0
  83. package/dist/css/value/values.js +131 -0
  84. package/dist/entities/architecture.d.ts +162 -0
  85. package/dist/entities/architecture.js +2 -0
  86. package/dist/entities/ast/assignments-nodes.d.ts +10 -0
  87. package/dist/entities/ast/assignments-nodes.js +64 -0
  88. package/dist/entities/ast/assignments-raw.d.ts +6 -0
  89. package/dist/entities/ast/assignments-raw.js +86 -0
  90. package/dist/entities/ast/assignments-tagged.d.ts +5 -0
  91. package/dist/entities/ast/assignments-tagged.js +180 -0
  92. package/dist/entities/ast/assignments.d.ts +9 -0
  93. package/dist/entities/ast/assignments.js +78 -0
  94. package/dist/entities/ast/branches.d.ts +4 -0
  95. package/dist/entities/ast/branches.js +32 -0
  96. package/dist/entities/ast/calls.d.ts +6 -0
  97. package/dist/entities/ast/calls.js +134 -0
  98. package/dist/entities/ast/classes.d.ts +5 -0
  99. package/dist/entities/ast/classes.js +57 -0
  100. package/dist/entities/ast/climb.d.ts +12 -0
  101. package/dist/entities/ast/climb.js +17 -0
  102. package/dist/entities/ast/comments.d.ts +4 -0
  103. package/dist/entities/ast/comments.js +100 -0
  104. package/dist/entities/ast/declaration.d.ts +4 -0
  105. package/dist/entities/ast/declaration.js +26 -0
  106. package/dist/entities/ast/depth.d.ts +17 -0
  107. package/dist/entities/ast/depth.js +149 -0
  108. package/dist/entities/ast/enums.d.ts +6 -0
  109. package/dist/entities/ast/enums.js +17 -0
  110. package/dist/entities/ast/file-exports.d.ts +7 -0
  111. package/dist/entities/ast/file-exports.js +78 -0
  112. package/dist/entities/ast/file-facts.d.ts +13 -0
  113. package/dist/entities/ast/file-facts.js +35 -0
  114. package/dist/entities/ast/file-imports.d.ts +5 -0
  115. package/dist/entities/ast/file-imports.js +77 -0
  116. package/dist/entities/ast/file.d.ts +5 -0
  117. package/dist/entities/ast/file.js +22 -0
  118. package/dist/entities/ast/functions.d.ts +8 -0
  119. package/dist/entities/ast/functions.js +102 -0
  120. package/dist/entities/ast/heritage.d.ts +4 -0
  121. package/dist/entities/ast/heritage.js +36 -0
  122. package/dist/entities/ast/index.d.ts +6 -0
  123. package/dist/entities/ast/index.js +125 -0
  124. package/dist/entities/ast/kind.d.ts +5 -0
  125. package/dist/entities/ast/kind.js +28 -0
  126. package/dist/entities/ast/loose.d.ts +37 -0
  127. package/dist/entities/ast/loose.js +2 -0
  128. package/dist/entities/ast/modifiers.d.ts +5 -0
  129. package/dist/entities/ast/modifiers.js +32 -0
  130. package/dist/entities/ast/project.d.ts +9 -0
  131. package/dist/entities/ast/project.js +75 -0
  132. package/dist/entities/ast/properties.d.ts +11 -0
  133. package/dist/entities/ast/properties.js +171 -0
  134. package/dist/entities/ast/resolve.d.ts +16 -0
  135. package/dist/entities/ast/resolve.js +307 -0
  136. package/dist/entities/ast/tree.d.ts +29 -0
  137. package/dist/entities/ast/tree.js +351 -0
  138. package/dist/entities/ast/types.d.ts +6 -0
  139. package/dist/entities/ast/types.js +45 -0
  140. package/dist/entities/ast/usage.d.ts +11 -0
  141. package/dist/entities/ast/usage.js +81 -0
  142. package/dist/entities/ast/variables.d.ts +8 -0
  143. package/dist/entities/ast/variables.js +91 -0
  144. package/dist/entities/context.d.ts +29 -0
  145. package/dist/entities/context.js +2 -0
  146. package/dist/entities/facts.d.ts +261 -0
  147. package/dist/entities/facts.js +2 -0
  148. package/dist/entities/findings.d.ts +19 -0
  149. package/dist/entities/findings.js +2 -0
  150. package/dist/entities/kinds.d.ts +40 -0
  151. package/dist/entities/kinds.js +221 -0
  152. package/dist/entities/location/homes.d.ts +28 -0
  153. package/dist/entities/location/homes.js +169 -0
  154. package/dist/entities/location/place.d.ts +10 -0
  155. package/dist/entities/location/place.js +56 -0
  156. package/dist/entities/location/where.d.ts +17 -0
  157. package/dist/entities/location/where.js +218 -0
  158. package/dist/entities/location.d.ts +16 -0
  159. package/dist/entities/location.js +140 -0
  160. package/dist/entities/operators.d.ts +14 -0
  161. package/dist/entities/operators.js +30 -0
  162. package/dist/entities/overview/data.d.ts +43 -0
  163. package/dist/entities/overview/data.js +2 -0
  164. package/dist/entities/overview/decision.d.ts +60 -0
  165. package/dist/entities/overview/decision.js +2 -0
  166. package/dist/entities/overview/file-tree.d.ts +10 -0
  167. package/dist/entities/overview/file-tree.js +2 -0
  168. package/dist/entities/overview/finding.d.ts +58 -0
  169. package/dist/entities/overview/finding.js +2 -0
  170. package/dist/entities/overview/graph.d.ts +65 -0
  171. package/dist/entities/overview/graph.js +2 -0
  172. package/dist/entities/overview/input.d.ts +15 -0
  173. package/dist/entities/overview/input.js +2 -0
  174. package/dist/entities/overview/summaries.d.ts +79 -0
  175. package/dist/entities/overview/summaries.js +2 -0
  176. package/dist/entities/place.d.ts +5 -0
  177. package/dist/entities/place.js +2 -0
  178. package/dist/entities/queries.d.ts +9 -0
  179. package/dist/entities/queries.js +305 -0
  180. package/dist/entities/repair.d.ts +16 -0
  181. package/dist/entities/repair.js +23 -0
  182. package/dist/entities/schema.d.ts +8 -0
  183. package/dist/entities/schema.js +23 -0
  184. package/dist/entities/story.d.ts +47 -0
  185. package/dist/entities/story.js +2 -0
  186. package/dist/entities/structure-facts.d.ts +11 -0
  187. package/dist/entities/structure-facts.js +2 -0
  188. package/dist/entities/token.d.ts +23 -0
  189. package/dist/entities/token.js +2 -0
  190. package/dist/entities/tree/build.d.ts +5 -0
  191. package/dist/entities/tree/build.js +252 -0
  192. package/dist/entities/tree/entries.d.ts +7 -0
  193. package/dist/entities/tree/entries.js +120 -0
  194. package/dist/entities/tree/index.d.ts +6 -0
  195. package/dist/entities/tree/index.js +21 -0
  196. package/dist/entities/tree/match.d.ts +17 -0
  197. package/dist/entities/tree/match.js +176 -0
  198. package/dist/frameworks/angular/index.d.ts +7 -0
  199. package/dist/frameworks/angular/index.js +17 -0
  200. package/dist/frameworks/facet.d.ts +16 -0
  201. package/dist/frameworks/facet.js +2 -0
  202. package/dist/frameworks/index.d.ts +9 -0
  203. package/dist/frameworks/index.js +120 -0
  204. package/dist/frameworks/react/index.d.ts +7 -0
  205. package/dist/frameworks/react/index.js +214 -0
  206. package/dist/frameworks/vue/index.d.ts +7 -0
  207. package/dist/frameworks/vue/index.js +17 -0
  208. package/dist/invariants/index.d.ts +6 -0
  209. package/dist/invariants/index.js +299 -0
  210. package/dist/invariants/list-vars.d.ts +5 -0
  211. package/dist/invariants/list-vars.js +143 -0
  212. package/dist/invariants/name.d.ts +16 -0
  213. package/dist/invariants/name.js +18 -0
  214. package/dist/invariants/normalize.d.ts +4 -0
  215. package/dist/invariants/normalize.js +95 -0
  216. package/dist/invariants/vars.d.ts +20 -0
  217. package/dist/invariants/vars.js +117 -0
  218. package/dist/main.d.ts +7 -0
  219. package/dist/main.js +229 -0
  220. package/dist/nodes/child-roles.d.ts +3 -0
  221. package/dist/nodes/child-roles.js +12 -0
  222. package/dist/nodes/children.d.ts +25 -0
  223. package/dist/nodes/children.js +112 -0
  224. package/dist/nodes/finally/emit.d.ts +6 -0
  225. package/dist/nodes/finally/emit.js +55 -0
  226. package/dist/nodes/finally/index.d.ts +8 -0
  227. package/dist/nodes/finally/index.js +35 -0
  228. package/dist/nodes/finally/queries.d.ts +5 -0
  229. package/dist/nodes/finally/queries.js +22 -0
  230. package/dist/nodes/finally/relations-access.d.ts +5 -0
  231. package/dist/nodes/finally/relations-access.js +46 -0
  232. package/dist/nodes/finally/relations-edge.d.ts +29 -0
  233. package/dist/nodes/finally/relations-edge.js +125 -0
  234. package/dist/nodes/finally/relations-group.d.ts +31 -0
  235. package/dist/nodes/finally/relations-group.js +103 -0
  236. package/dist/nodes/finally/relations.d.ts +5 -0
  237. package/dist/nodes/finally/relations.js +81 -0
  238. package/dist/nodes/finally/required.d.ts +5 -0
  239. package/dist/nodes/finally/required.js +90 -0
  240. package/dist/nodes/finally/roles.d.ts +13 -0
  241. package/dist/nodes/finally/roles.js +41 -0
  242. package/dist/nodes/finally/violation.d.ts +17 -0
  243. package/dist/nodes/finally/violation.js +2 -0
  244. package/dist/nodes/similar.d.ts +21 -0
  245. package/dist/nodes/similar.js +156 -0
  246. package/dist/pipeline-facts.d.ts +11 -0
  247. package/dist/pipeline-facts.js +112 -0
  248. package/dist/pipeline-roles.d.ts +6 -0
  249. package/dist/pipeline-roles.js +75 -0
  250. package/dist/pipeline-unroled.d.ts +14 -0
  251. package/dist/pipeline-unroled.js +193 -0
  252. package/dist/pipeline.d.ts +7 -0
  253. package/dist/pipeline.js +73 -0
  254. package/dist/plugin.d.ts +2 -0
  255. package/dist/plugin.js +3 -0
  256. package/dist/report/asks.d.ts +55 -0
  257. package/dist/report/asks.js +50 -0
  258. package/dist/report/cli-report.d.ts +2 -0
  259. package/dist/report/cli-report.js +13 -0
  260. package/dist/report/config-error-guard.d.ts +8 -0
  261. package/dist/report/config-error-guard.js +5 -0
  262. package/dist/report/configErrors.d.ts +98 -0
  263. package/dist/report/configErrors.js +75 -0
  264. package/dist/report/errorTypes/codes/structure.d.ts +15 -0
  265. package/dist/report/errorTypes/codes/structure.js +76 -0
  266. package/dist/report/errorTypes/decision-maker.d.ts +23 -0
  267. package/dist/report/errorTypes/decision-maker.js +99 -0
  268. package/dist/report/errorTypes/destinations.d.ts +38 -0
  269. package/dist/report/errorTypes/destinations.js +147 -0
  270. package/dist/report/errorTypes/finding-type.d.ts +11 -0
  271. package/dist/report/errorTypes/finding-type.js +2 -0
  272. package/dist/report/errorTypes/index.d.ts +15 -0
  273. package/dist/report/errorTypes/index.js +45 -0
  274. package/dist/report/errorTypes/types/fileContents.d.ts +9 -0
  275. package/dist/report/errorTypes/types/fileContents.js +34 -0
  276. package/dist/report/errorTypes/types/unknownRole.d.ts +9 -0
  277. package/dist/report/errorTypes/types/unknownRole.js +22 -0
  278. package/dist/report/errorTypes/types/wrongAction.d.ts +22 -0
  279. package/dist/report/errorTypes/types/wrongAction.js +135 -0
  280. package/dist/report/errorTypes/types/wrongPlacement.d.ts +9 -0
  281. package/dist/report/errorTypes/types/wrongPlacement.js +57 -0
  282. package/dist/report/errorTypes/vocabulary/ids.d.ts +5 -0
  283. package/dist/report/errorTypes/vocabulary/ids.js +16 -0
  284. package/dist/report/errorTypes/vocabulary/phrases.d.ts +10 -0
  285. package/dist/report/errorTypes/vocabulary/phrases.js +174 -0
  286. package/dist/report/errorTypes/vocabulary/places.d.ts +8 -0
  287. package/dist/report/errorTypes/vocabulary/places.js +36 -0
  288. package/dist/report/errorTypes/vocabulary/verbs.d.ts +7 -0
  289. package/dist/report/errorTypes/vocabulary/verbs.js +30 -0
  290. package/dist/report/finding-from.d.ts +9 -0
  291. package/dist/report/finding-from.js +103 -0
  292. package/dist/report/notices.d.ts +4 -0
  293. package/dist/report/notices.js +31 -0
  294. package/dist/report/render-report.d.ts +12 -0
  295. package/dist/report/render-report.js +142 -0
  296. package/dist/report/user-report/build/bundle.d.ts +3 -0
  297. package/dist/report/user-report/build/bundle.js +169 -0
  298. package/dist/report/user-report/build/bundle.prebuilt.js +760 -0
  299. package/dist/report/user-report/data/collect.d.ts +4 -0
  300. package/dist/report/user-report/data/collect.js +80 -0
  301. package/dist/report/user-report/data/file-tree.d.ts +9 -0
  302. package/dist/report/user-report/data/file-tree.js +72 -0
  303. package/dist/report/user-report/data/finding-boundary.d.ts +9 -0
  304. package/dist/report/user-report/data/finding-boundary.js +21 -0
  305. package/dist/report/user-report/data/finding-plan.d.ts +16 -0
  306. package/dist/report/user-report/data/finding-plan.js +45 -0
  307. package/dist/report/user-report/data/finding-title.d.ts +12 -0
  308. package/dist/report/user-report/data/finding-title.js +36 -0
  309. package/dist/report/user-report/data/findings.d.ts +10 -0
  310. package/dist/report/user-report/data/findings.js +171 -0
  311. package/dist/report/user-report/data/graph-edges.d.ts +19 -0
  312. package/dist/report/user-report/data/graph-edges.js +109 -0
  313. package/dist/report/user-report/data/graph-helpers.d.ts +7 -0
  314. package/dist/report/user-report/data/graph-helpers.js +67 -0
  315. package/dist/report/user-report/data/graph-roles.d.ts +5 -0
  316. package/dist/report/user-report/data/graph-roles.js +71 -0
  317. package/dist/report/user-report/data/graph.d.ts +11 -0
  318. package/dist/report/user-report/data/graph.js +90 -0
  319. package/dist/report/user-report/data/invariants.d.ts +7 -0
  320. package/dist/report/user-report/data/invariants.js +62 -0
  321. package/dist/report/user-report/data/nodes.d.ts +11 -0
  322. package/dist/report/user-report/data/nodes.js +106 -0
  323. package/dist/report/user-report/data/role-examples.d.ts +16 -0
  324. package/dist/report/user-report/data/role-examples.js +94 -0
  325. package/dist/report/user-report/data/role-filters.d.ts +15 -0
  326. package/dist/report/user-report/data/role-filters.js +79 -0
  327. package/dist/report/user-report/data/role-marks.d.ts +5 -0
  328. package/dist/report/user-report/data/role-marks.js +79 -0
  329. package/dist/report/user-report/data/roles.d.ts +7 -0
  330. package/dist/report/user-report/data/roles.js +83 -0
  331. package/dist/report/user-report/data/scan.d.ts +8 -0
  332. package/dist/report/user-report/data/scan.js +59 -0
  333. package/dist/report/user-report/html/shell.d.ts +3 -0
  334. package/dist/report/user-report/html/shell.js +27 -0
  335. package/dist/report/user-report/index.d.ts +8 -0
  336. package/dist/report/user-report/index.js +48 -0
  337. package/dist/report/user-report/shared/describe.d.ts +7 -0
  338. package/dist/report/user-report/shared/describe.js +86 -0
  339. package/dist/scripts/audit-report.d.ts +2 -0
  340. package/dist/scripts/audit-report.js +147 -0
  341. package/dist/utils/accumulate.d.ts +6 -0
  342. package/dist/utils/accumulate.js +18 -0
  343. package/dist/utils/article.d.ts +2 -0
  344. package/dist/utils/article.js +12 -0
  345. package/dist/utils/classify.d.ts +12 -0
  346. package/dist/utils/classify.js +25 -0
  347. package/dist/utils/configs.d.ts +25 -0
  348. package/dist/utils/configs.js +87 -0
  349. package/dist/utils/count.d.ts +7 -0
  350. package/dist/utils/count.js +13 -0
  351. package/dist/utils/dispatch.d.ts +2 -0
  352. package/dist/utils/dispatch.js +27 -0
  353. package/dist/utils/distinct.d.ts +2 -0
  354. package/dist/utils/distinct.js +12 -0
  355. package/dist/utils/field.d.ts +14 -0
  356. package/dist/utils/field.js +60 -0
  357. package/dist/utils/file-name.d.ts +2 -0
  358. package/dist/utils/file-name.js +11 -0
  359. package/dist/utils/files.d.ts +7 -0
  360. package/dist/utils/files.js +73 -0
  361. package/dist/utils/fixpoint.d.ts +2 -0
  362. package/dist/utils/fixpoint.js +19 -0
  363. package/dist/utils/gate.d.ts +2 -0
  364. package/dist/utils/gate.js +12 -0
  365. package/dist/utils/group.d.ts +3 -0
  366. package/dist/utils/group.js +33 -0
  367. package/dist/utils/host.d.ts +3 -0
  368. package/dist/utils/host.js +13 -0
  369. package/dist/utils/imports.d.ts +12 -0
  370. package/dist/utils/imports.js +121 -0
  371. package/dist/utils/judged.d.ts +5 -0
  372. package/dist/utils/judged.js +19 -0
  373. package/dist/utils/keyed.d.ts +2 -0
  374. package/dist/utils/keyed.js +23 -0
  375. package/dist/utils/map-record.d.ts +2 -0
  376. package/dist/utils/map-record.js +11 -0
  377. package/dist/utils/path-label.d.ts +6 -0
  378. package/dist/utils/path-label.js +35 -0
  379. package/dist/utils/pattern.d.ts +18 -0
  380. package/dist/utils/pattern.js +191 -0
  381. package/dist/utils/permission.d.ts +16 -0
  382. package/dist/utils/permission.js +16 -0
  383. package/dist/utils/plural.d.ts +2 -0
  384. package/dist/utils/plural.js +9 -0
  385. package/dist/utils/qualified.d.ts +2 -0
  386. package/dist/utils/qualified.js +21 -0
  387. package/dist/utils/rank.d.ts +2 -0
  388. package/dist/utils/rank.js +24 -0
  389. package/dist/utils/read-field.d.ts +12 -0
  390. package/dist/utils/read-field.js +50 -0
  391. package/dist/utils/read-when.d.ts +2 -0
  392. package/dist/utils/read-when.js +17 -0
  393. package/dist/utils/reason.d.ts +4 -0
  394. package/dist/utils/reason.js +9 -0
  395. package/dist/utils/record.d.ts +3 -0
  396. package/dist/utils/record.js +21 -0
  397. package/dist/utils/resolve.d.ts +2 -0
  398. package/dist/utils/resolve.js +24 -0
  399. package/dist/utils/search.d.ts +2 -0
  400. package/dist/utils/search.js +16 -0
  401. package/dist/utils/seen.d.ts +6 -0
  402. package/dist/utils/seen.js +27 -0
  403. package/dist/utils/span.d.ts +5 -0
  404. package/dist/utils/span.js +2 -0
  405. package/dist/utils/speak.d.ts +2 -0
  406. package/dist/utils/speak.js +18 -0
  407. package/dist/utils/split.d.ts +8 -0
  408. package/dist/utils/split.js +8 -0
  409. package/dist/utils/template.d.ts +5 -0
  410. package/dist/utils/template.js +5 -0
  411. package/dist/utils/text.d.ts +4 -0
  412. package/dist/utils/text.js +42 -0
  413. package/dist/utils/tokenize.d.ts +2 -0
  414. package/dist/utils/tokenize.js +13 -0
  415. package/dist/utils/try-read.d.ts +4 -0
  416. package/dist/utils/try-read.js +24 -0
  417. package/dist/utils/typed-field.d.ts +3 -0
  418. package/dist/utils/typed-field.js +16 -0
  419. package/dist/utils/verdicts.d.ts +4 -0
  420. package/dist/utils/verdicts.js +20 -0
  421. package/entities/operators.ts +31 -0
  422. package/package.json +62 -19
  423. package/report/errorTypes/vocabulary/ids.ts +12 -0
  424. package/report/errorTypes/vocabulary/phrases.ts +161 -0
  425. package/report/errorTypes/vocabulary/places.ts +46 -0
  426. package/report/errorTypes/vocabulary/verbs.ts +31 -0
  427. package/report/user-report/shared/describe.ts +107 -0
  428. package/ast.js +0 -107
  429. package/bin/follow-architecture.js +0 -6
  430. package/config.js +0 -82
  431. package/entities/aliases.js +0 -10
  432. package/entities/invariants.js +0 -134
  433. package/entities/nodes.js +0 -112
  434. package/main.js +0 -95
  435. package/report.js +0 -73
  436. package/utils.js +0 -104
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.criteriaOf = exports.similarNodes = void 0;
27
+ // HOW MUCH a folder LOOKS LIKE a declared entity — measured in ROLES, not in
28
+ // file names.
29
+ //
30
+ // A folder is a feature when the code inside it IS the code a feature holds: a
31
+ // store model, actions, a controller. Whether the file is called `store.ts` or
32
+ // `whatever.ts` says nothing — the ROLE of the code does. So each declared
33
+ // entity contributes the roles its children declare, the folder contributes the
34
+ // roles its files actually have (classified exactly like everything else), and
35
+ // the score is the share of the entity's roles that are already there.
36
+ //
37
+ // Only entities at or above the threshold are offered, and ALL of them are: a
38
+ // folder can be 80% a feature and 66% a type home, and both are true answers.
39
+ // Shapes come from the tree, the threshold from the rule option (`similarity`,
40
+ // default 60%).
41
+ const fs = __importStar(require("node:fs"));
42
+ const path = __importStar(require("node:path"));
43
+ const notices_1 = require("../report/notices");
44
+ const pattern_1 = require("../utils/pattern");
45
+ const ast_1 = require("../entities/ast");
46
+ const classify_1 = require("../code-roles/classify");
47
+ const location_1 = require("../entities/location");
48
+ const try_read_1 = require("../utils/try-read");
49
+ const reason_1 = require("../utils/reason");
50
+ const distinct_1 = require("../utils/distinct");
51
+ const rank_1 = require("../utils/rank");
52
+ const child_roles_1 = require("./child-roles");
53
+ // The roles an entity is MADE OF — one criterion per role, not per file.
54
+ // The distinct-collect walk is the shared `distinctFlat` core; the child's
55
+ // roles are the shared `rolesOfChild` reading.
56
+ const criteriaOf = (arch, node) => {
57
+ const children = node.children ?? [];
58
+ return (0, distinct_1.distinctFlat)(children, (c) => (0, child_roles_1.rolesOfChild)(arch, c));
59
+ };
60
+ exports.criteriaOf = criteriaOf;
61
+ // The files that belong to this folder: the entity's children live at the top of
62
+ // it and one level down (`actions/x.ts`).
63
+ const filesIn = (folder, repoFiles) => {
64
+ const depth = (0, location_1.segmentsOf)(folder).length;
65
+ return (repoFiles ?? []).filter((file) => file.startsWith(`${folder}/`) && (0, location_1.segmentsOf)(file).length - depth <= 2);
66
+ };
67
+ // The roles one file's code has, parsed and classified exactly like everything
68
+ // else. A file outside the project contributes no roles — and says why,
69
+ // because "no roles" and "could not look" are different answers.
70
+ const rolesOfFile = (rel, ctx) => (0, try_read_1.readOrFallback)(rel, (file) => {
71
+ const abs = path.join(ctx.repoRoot, file);
72
+ const sf = (0, ast_1.loadSourceFile)(ctx.project, abs, fs.readFileSync(abs, "utf8"));
73
+ const importMap = (0, ast_1.importNameModules)(sf, ctx.repoRoot, ctx.aliases ?? {}, ctx.repoFiles);
74
+ const candidates = (0, ast_1.collectCandidates)(sf, importMap, file, ctx.repoRoot);
75
+ return (0, classify_1.classifyRoles)(candidates, ctx.arch?.codeRoles ?? {}, ctx.arch).present;
76
+ }, [], (e) => (0, notices_1.notice)(`the roles in ${rel} could not be read`, (0, reason_1.reasonOf)(e)));
77
+ // The roles the folder's code actually has. Parsed and classified once per file
78
+ // per run — the folder is judged by the same facts its own findings come from.
79
+ const rolesInFolder = (ctx, folder) => {
80
+ const roles = new Set();
81
+ const cache = (ctx.cache ??= { files: new Map() });
82
+ for (const rel of filesIn(folder, ctx.repoFiles)) {
83
+ if (!cache.files.has(rel))
84
+ cache.files.set(rel, rolesOfFile(rel, ctx));
85
+ for (const role of cache.files.get(rel) ?? [])
86
+ roles.add(role);
87
+ }
88
+ return roles;
89
+ };
90
+ // Whether this folder IS this entity — the node's path as a template, matched
91
+ // against the concrete folder (`apps/backend/{kebab-case}` ← `apps/backend/document`).
92
+ const isOwnPath = (node, folder) => (node.variants ?? [])
93
+ .map((v) => v.path)
94
+ .concat(node.path ? [node.path] : [])
95
+ .some((template) => (0, pattern_1.compilePattern)(template).re.test(folder));
96
+ // Lookalikes answer ONE question: "this folder is declared nowhere — what does it
97
+ // look like?" A folder the architecture already places gets a precise answer from
98
+ // the role homes (`placeFor`), and offering it a sibling entity made of the same
99
+ // roles only says "move an action out of `actions/`", which is not its problem:
100
+ // its problem is that a piece inside it fits no declared role.
101
+ const isDeclaredPath = (arch, folder) => (arch.nodes.all ?? []).some((n) => isOwnPath(n, folder));
102
+ // TWO SIDES OF ONE COMPARISON. The entity must cover most of its OWN shape
103
+ // (`commands` declares two roles and every folder holding both is 2/2 —
104
+ // "looks like a command folder" was true of a whole feature), AND the entity
105
+ // must account for most of what the folder actually holds, or it explains
106
+ // only a corner of it and is not a shape this folder has.
107
+ const resembles = (criteria, present, threshold) => {
108
+ // A shape needs at least two roles to be a shape: an entity declaring one
109
+ // role would match half the folders in any repo.
110
+ if (criteria.length < 2)
111
+ return null;
112
+ const hit = criteria.filter((role) => present.has(role));
113
+ const score = hit.length / criteria.length;
114
+ if (score < threshold || hit.length / present.size < threshold)
115
+ return null;
116
+ return hit;
117
+ };
118
+ // The offer one entity makes: its shape, measured against what the folder
119
+ // holds. The entity the folder ALREADY is is never a destination: `document`
120
+ // is an instance of `apps/backend/{kebab-case}`, and the variant's own path is
121
+ // a template — comparing it as text never matched, so the offer read "move
122
+ // this feature's controller into this feature".
123
+ // The offer a measured hit earns: the entity's own path, its score, its roles.
124
+ const offerOf = (node, hit, total) => ({
125
+ slug: node.slug,
126
+ path: node.variants?.[0]?.path ?? node.path ?? null,
127
+ score: hit.length / total,
128
+ hit: hit.length,
129
+ total,
130
+ roles: hit,
131
+ });
132
+ const lookalikeOf = (node, folder, match) => {
133
+ const criteria = criteriaOf(match.arch, node);
134
+ const hit = isOwnPath(node, folder) ? null : resembles(criteria, match.present, match.threshold);
135
+ return hit ? offerOf(node, hit, criteria.length) : null;
136
+ };
137
+ // The folder's own role set, when there is anything to compare: a folder the
138
+ // architecture already declares (or that holds no classifiable code) has no
139
+ // lookalike question to answer.
140
+ const folderRoles = (arch, folder, ctx) => {
141
+ if (!ctx?.project || isDeclaredPath(arch, folder))
142
+ return null;
143
+ const present = rolesInFolder({ ...ctx, arch }, folder);
144
+ return present.size ? present : null;
145
+ };
146
+ // The declared entities this folder resembles, best first. `score` is the share
147
+ // of the entity's roles the folder already holds. The score-keep-rank walk is
148
+ // the shared `rankedOffers` core.
149
+ const similarNodes = (arch, folder, ctx, threshold = arch.similarity ?? pattern_1.DEFAULT_SIMILARITY) => {
150
+ const present = folderRoles(arch, folder, ctx);
151
+ if (!present)
152
+ return [];
153
+ const match = { arch, present, threshold };
154
+ return (0, rank_1.rankedOffers)(arch.nodes.all ?? [], (node) => lookalikeOf(node, folder, match), (a, b) => b.score - a.score || a.slug.localeCompare(b.slug));
155
+ };
156
+ exports.similarNodes = similarNodes;
@@ -0,0 +1,11 @@
1
+ import type { Project } from "ts-morph";
2
+ import type { Arch } from "./entities/architecture";
3
+ import type { FileContext } from "./entities/context";
4
+ import type { Candidate, FileFacts } from "./entities/facts";
5
+ import type { SeenStore } from "./utils/seen";
6
+ declare const collectFacts: (abs: string, arch: Arch, project: Project, repoFiles: string[], dedupe: SeenStore) => {
7
+ ctx: FileContext;
8
+ candidates: Candidate[];
9
+ fileFacts: FileFacts;
10
+ };
11
+ export { collectFacts };
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.collectFacts = void 0;
27
+ // The FACTS phase of the per-file pipeline: load the source file, collect the
28
+ // candidates once, attach the facet readings (framework, CSS, call depth), and
29
+ // build the file's fact set. Classification and the file facts both consume the
30
+ // same candidates, so nothing is collected twice.
31
+ const path = __importStar(require("node:path"));
32
+ const fs = __importStar(require("node:fs"));
33
+ const imports_1 = require("./utils/imports");
34
+ const ast_1 = require("./entities/ast");
35
+ const css_1 = require("./css");
36
+ const values_1 = require("./css/value/values");
37
+ const frameworks_1 = require("./frameworks");
38
+ const depth_1 = require("./entities/ast/depth");
39
+ // The file's place and the run's shared state, before any fact is collected.
40
+ const buildFileContext = (abs, arch, load) => {
41
+ const repoRoot = arch.repoRoot ?? ".";
42
+ const rel = (0, imports_1.toRel)(repoRoot, abs);
43
+ return {
44
+ abs,
45
+ rel,
46
+ dir: path.posix.dirname(rel),
47
+ basename: path.posix.basename(rel),
48
+ sf: load.sf,
49
+ repoRoot,
50
+ aliases: arch.aliases ?? {},
51
+ // The built architecture — scope entries (`{ node: slug }`) resolve
52
+ // against the tree, and filters may reference it too.
53
+ arch,
54
+ roles: [],
55
+ roleCtx: null,
56
+ facts: null,
57
+ repoFiles: load.repoFiles,
58
+ // Shared across the run: lets node-level checks report once per folder
59
+ // instead of once per file inside it.
60
+ dedupe: load.dedupe,
61
+ };
62
+ };
63
+ const classifyMembers = (members) => {
64
+ for (const member of members ?? []) {
65
+ if (typeof member.value === "string")
66
+ member.css = (0, values_1.classifyValue)(member.value, member.line ?? null);
67
+ classifyMembers(member.members);
68
+ }
69
+ };
70
+ // The candidates with every facet reading attached: call depth (a FACT, so a
71
+ // rule can refuse a chain nobody can follow), the framework and style readings
72
+ // of the same AST (attached before classification, so a code role can be
73
+ // defined on them exactly like on `kind` — both are optional namespaces, a
74
+ // plain `.ts` file gets neither), and the CSS grammar reading of string members.
75
+ const withFacets = (candidates, run) => {
76
+ const { ctx, sf, text, project, arch, repoFiles, importMap } = run;
77
+ (0, depth_1.attachCallDepth)(candidates, {
78
+ rel: ctx.rel,
79
+ project,
80
+ repoRoot: arch.repoRoot ?? ctx.repoRoot ?? ".",
81
+ aliases: ctx.aliases,
82
+ repoFiles,
83
+ cache: (arch.depthCache ??= { memo: new Map(), files: new Map() }),
84
+ });
85
+ (0, frameworks_1.enrich)(candidates, { rel: ctx.rel, sf, text, repoRoot: arch.repoRoot ?? ctx.repoRoot, importMap });
86
+ (0, css_1.attachToCandidates)(candidates, { sf });
87
+ for (const candidate of candidates)
88
+ classifyMembers(candidate.kind?.initializer?.members);
89
+ return candidates;
90
+ };
91
+ // Load → candidates → facets → file facts. The file's facts are needed BEFORE
92
+ // classification — a role may be recognised by what the file depends on
93
+ // (`file.imports`), not only by the candidate's own shape. The only fields that
94
+ // need the classification are `candidates` and `roles`, so they are filled in
95
+ // afterwards; every candidate holds the same facts object, so `infer` sees
96
+ // everything the file facts offer, not a hand-picked subset.
97
+ const collectFacts = (...args) => {
98
+ const [abs, arch, project, repoFiles, dedupe] = args;
99
+ const text = fs.readFileSync(abs, "utf8");
100
+ const sf = (0, ast_1.loadSourceFile)(project, abs, text);
101
+ const ctx = buildFileContext(abs, arch, { sf, repoFiles, dedupe });
102
+ const importMap = (0, ast_1.importNameModules)(sf, ctx.repoRoot ?? ".", ctx.aliases, repoFiles);
103
+ // `repoRoot` lets the type-resolved facts (`assignments[].type`,
104
+ // `parameters[].typeFile`) be repo-relative, which is what
105
+ // `location: { node: … }` matches against.
106
+ const candidates = withFacets((0, ast_1.collectCandidates)(sf, importMap, ctx.rel, ctx.repoRoot ?? "."), { ctx, sf, text, project, arch, repoFiles, importMap });
107
+ const fileFacts = (0, ast_1.collectFileFacts)(sf, { rel: ctx.rel, repoFiles, aliases: ctx.aliases, repoRoot: ctx.repoRoot ?? ".", candidates: [] });
108
+ for (const c of candidates)
109
+ c.file = fileFacts;
110
+ return { ctx, candidates, fileFacts };
111
+ };
112
+ exports.collectFacts = collectFacts;
@@ -0,0 +1,6 @@
1
+ import type { Arch } from "./entities/architecture";
2
+ import type { FileContext } from "./entities/context";
3
+ import type { Candidate } from "./entities/facts";
4
+ import type { Finding } from "./entities/findings";
5
+ declare const checkRoleHomes: (withRoles: readonly Candidate[], ctx: FileContext, arch: Arch, out: Finding[]) => void;
6
+ export { checkRoleHomes };
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkRoleHomes = void 0;
4
+ // The ROLE-HOME phase: every candidate must fit its ROLE's declared home. A
5
+ // role says where its code may be declared; code of that role anywhere else is
6
+ // reported with the place it belongs. ONE finding per role per file — four
7
+ // helpers in one file are one decision, not four copies of the same sentence.
8
+ const location_1 = require("./entities/location");
9
+ const finally_1 = require("./nodes/finally");
10
+ const asks_1 = require("./report/asks");
11
+ const cli_report_1 = require("./report/cli-report");
12
+ const qualified_1 = require("./utils/qualified");
13
+ // Is this candidate a misfit? A role's report is about a NAME: an anonymous
14
+ // function is the argument or the body of something else, and naming it would
15
+ // produce a sentence with a hole in it. A role nobody declares, or one with no
16
+ // home, restricts nothing. The guards are the shared qualified-answer walk;
17
+ // the home question is `fitsRole`'s own.
18
+ const misfitRoleOf = (c, arch, rel) => (0, qualified_1.answerWhenAllPass)(c, [(x) => Boolean(x.role && arch.codeRoles?.[x.role] && x.name), (x) => (0, location_1.homesOf)(arch, x.role ?? "").length > 0, (x) => !(0, finally_1.fitsRole)(x.role ?? "", arch, rel)], (x) => x.role ?? null);
19
+ // The misfits by role: every named candidate of a declared role with homes,
20
+ // sitting outside every one of them.
21
+ const misfitsOf = (withRoles, arch, rel) => {
22
+ const misfits = new Map();
23
+ for (const c of withRoles) {
24
+ const role = misfitRoleOf(c, arch, rel);
25
+ if (!role || !c.name)
26
+ continue;
27
+ misfits.set(role, [...(misfits.get(role) ?? []), { name: c.name, line: c.lines?.[0] ?? 1 }]);
28
+ }
29
+ return misfits;
30
+ };
31
+ // The reason a misfit is a misfit: the role's own wording when the config has
32
+ // one (a clause, not a sentence — the subject and the place are the frame's
33
+ // job), else the plain statement of what the code is and what to fill in.
34
+ const whyOf = (role, names, place, arch) => {
35
+ const own = arch.codeRoles[role].report;
36
+ const ownMessage = typeof own === "object" && own !== null ? own.message : null;
37
+ if (ownMessage)
38
+ return ownMessage;
39
+ // A role with NO place for this file must not reach `place.path`: widening the
40
+ // rules to `packages` put such a file in front of this line and it crashed.
41
+ const fill = !place || place.concrete ? "" : `; fill ${(0, location_1.placeholdersOf)(place.path)} for the instance this code belongs to`;
42
+ return `${names.length > 1 ? "They are" : "It is"} \`${role}\` code${fill}.`;
43
+ };
44
+ // One role's misfit finding: the demand and its sentence come from the ONE
45
+ // vocabulary in report/asks — "this code belongs elsewhere" is a `move`, said
46
+ // the same way here and in the folder check. The BOX the sentence names is
47
+ // resolved here, once, so the picture and the sentence cannot disagree.
48
+ const misfitFinding = (role, found, ctx, arch) => {
49
+ const names = found.map((x) => x.name);
50
+ const list = names.map((n) => `\`${n}\``).join(", ");
51
+ // WHERE this code belongs — asked of the ONE implementation in homes, so
52
+ // this message and the folder-level one can never name different places.
53
+ const place = (0, location_1.placeFor)(arch, role, ctx.rel);
54
+ const where = place ? `\`${place.path}\`` : null;
55
+ const report = asks_1.asks.move({
56
+ what: list,
57
+ to: where,
58
+ plural: names.length > 1,
59
+ node: (0, location_1.boxOfPlace)(arch, place?.path),
60
+ // The path WITHOUT backticks: the text decorates, the data does not.
61
+ path: place?.path ?? null,
62
+ // `findingFrom` substitutes `{what}` / `{destination}` from the vars below.
63
+ why: whyOf(role, names, place, arch),
64
+ });
65
+ return (0, cli_report_1.findingFrom)({ report, line: found[0].line }, "codeRoles", role, `role:${role}:report`, {
66
+ path: ctx.rel,
67
+ what: names.join(", "),
68
+ destination: place?.path ?? null,
69
+ });
70
+ };
71
+ const checkRoleHomes = (withRoles, ctx, arch, out) => {
72
+ for (const [role, found] of misfitsOf(withRoles, arch, ctx.rel))
73
+ out.push(misfitFinding(role, found, ctx, arch));
74
+ };
75
+ exports.checkRoleHomes = checkRoleHomes;
@@ -0,0 +1,14 @@
1
+ import type { Project } from "ts-morph";
2
+ import type { Arch } from "./entities/architecture";
3
+ import type { FileContext } from "./entities/context";
4
+ import type { Candidate } from "./entities/facts";
5
+ import type { Finding } from "./entities/findings";
6
+ declare const checkUnroled: (withRoles: readonly Candidate[], run: {
7
+ present: readonly string[];
8
+ ctx: FileContext;
9
+ arch: Arch;
10
+ project: Project;
11
+ repoFiles: string[];
12
+ out: Finding[];
13
+ }) => void;
14
+ export { checkUnroled };
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checkUnroled = void 0;
4
+ const tree_1 = require("./entities/tree");
5
+ const location_1 = require("./entities/location");
6
+ const similar_1 = require("./nodes/similar");
7
+ const kinds_1 = require("./entities/kinds");
8
+ const asks_1 = require("./report/asks");
9
+ const cli_report_1 = require("./report/cli-report");
10
+ const speak_1 = require("./utils/speak");
11
+ const field_1 = require("./utils/field");
12
+ const child_roles_1 = require("./nodes/child-roles");
13
+ // The child whose PATTERN this file matches — `store.ts` literally,
14
+ // `{kebab-case}.ts` by the convention it is written in. One rule, the same one
15
+ // the tree uses.
16
+ const ownChildOf = (kids, basename) => kids.find((k) => !k.folder && k.re.test(basename)) ?? null;
17
+ // The roles this place declares: the child whose pattern the file matches,
18
+ // else — for a file NODE (`apps/backend/{kebab-case}/controller.ts` is a node
19
+ // of its own) — the node's own roles. Nothing lists a file node as a child, so
20
+ // its own roles are what applies here. The child's roles are the shared
21
+ // `rolesOfChild` reading.
22
+ const declaredRolesOf = (match, own, arch) => {
23
+ const childRoles = (0, child_roles_1.rolesOfChild)(arch, own);
24
+ if (childRoles.length)
25
+ return childRoles;
26
+ const isFileNode = (match?.node?.variants ?? []).some((v) => v.isFile);
27
+ return isFileNode ? (match?.node?.roles ?? []) : [];
28
+ };
29
+ const declarationOf = (ctx, arch) => {
30
+ const match = (0, tree_1.deepestMatch)(ctx.rel, arch);
31
+ const owner = match?.node?.slug ?? null;
32
+ const kids = owner ? (arch.nodes.bySlug[owner]?.children ?? []) : [];
33
+ const own = ownChildOf(kids, ctx.basename ?? "");
34
+ return { owner, declaredHere: declaredRolesOf(match, own, arch) };
35
+ };
36
+ // The roles a place declares, in the reader's words.
37
+ const listOf = (roles) => roles.map((r) => `\`${r}\``).join(" / ");
38
+ // The piece's own words for what it IS: a local alias, a wrapper, a write, the
39
+ // declaration's text — each fact answers before the generic fallback.
40
+ const aliasShape = (c) => {
41
+ const reads = (0, field_1.fieldOf)(c, "reads");
42
+ const read = (0, field_1.isList)(reads) && (0, field_1.isObj)(reads[0]) ? reads[0] : null;
43
+ if (!read)
44
+ return null;
45
+ return `a local alias of \`${read.what}${read.what ? " " : ""}\`${read.module ? `read from \`${read.module}\`` : ""}`;
46
+ };
47
+ const wrapperShape = (c) => {
48
+ const call = (c.calls ?? []).find((x) => x.module && !x.receiverOnly);
49
+ if (!call)
50
+ return null;
51
+ return `a wrapper around \`${call.action ?? "a call"}\`${call.module ? ` of \`${call.module}\`` : ""}`;
52
+ };
53
+ const declarationShape = (c) => {
54
+ const write = (c.assignments ?? [])[0];
55
+ if (write)
56
+ return `a write into \`${write.target}\``;
57
+ // The declaration itself: `const commands = root.commands` says more than
58
+ // "a plain variable" ever could.
59
+ const text = c.text ?? null;
60
+ if (text && text.length <= 90)
61
+ return `the declaration \`${text.replace(/\s+/g, " ")}\``;
62
+ return null;
63
+ };
64
+ // WHAT the piece IS, in its own words. "this is something else" told the
65
+ // reader nothing; the piece's own facts say what it is and where it came from.
66
+ const shapeOf = (c) => {
67
+ if (!c)
68
+ return null;
69
+ const specific = aliasShape(c) ?? wrapperShape(c) ?? declarationShape(c);
70
+ if (specific)
71
+ return specific;
72
+ return (c.kind?.own?.is ?? "") === "VariableDeclaration" ? "a plain variable" : "a plain function";
73
+ };
74
+ // The reason a piece has no role: what the place declares (and what the piece
75
+ // is), or that nothing declares this file, or that it is outside the tree.
76
+ const whyUnroled = (ctx, decl, piece, offered) => {
77
+ const shape = shapeOf(piece);
78
+ const what2 = shape ? `this is ${shape} — not code a role describes` : "this is something else";
79
+ if (decl.declaredHere.length)
80
+ return `only ${listOf(decl.declaredHere)} is declared here, and ${what2}.${offered}`;
81
+ if (decl.owner)
82
+ return `nothing declares which kind of code \`${ctx.rel}\` holds.${offered}`;
83
+ return `\`${ctx.rel}\` is outside the node tree.${offered}`;
84
+ };
85
+ // What the folder looks like, in the reader's words: the entities it resembles
86
+ // and how much of each it holds.
87
+ const lookalikeText = (like) => (like.length ? ` It looks like ${like.map((n) => `\`${n.path ?? n.slug}\` (${n.hit}/${n.total})`).join(" or ")}.` : "");
88
+ // "Nothing describes this code" — one of the four demands in report/asks, so
89
+ // the sentence and the repair read the same here as anywhere else. Moving is
90
+ // offered only where the folder really resembles something — the destination
91
+ // is the entity's own words, and there may be several.
92
+ const noRole = (what, piece, view) => {
93
+ const demand = asks_1.asks.role({ what: `\`${what}\``, why: whyUnroled(view.ctx, view.decl, piece, lookalikeText(view.like)) });
94
+ if (!view.like.length)
95
+ return demand;
96
+ demand.fix = `Move \`${what}\` into ${view.like.map((n) => `\`${n.path ?? n.slug}\``).join(" or ")} — this folder already has ${view.like[0].hit} of the ${view.like[0].total} things that entity declares.`;
97
+ return demand;
98
+ };
99
+ // A PIECE is a candidate that can carry a role. Every candidate the AST layer
100
+ // collects is one, except two structural cases: a variable declared INSIDE a
101
+ // function (the function answers for it) and an anonymous function handed
102
+ // straight to a call — that is the call's ARGUMENT (`.map(x => …)`), not code
103
+ // with a life of its own. A `const` is a piece only at MODULE scope.
104
+ const isPiece = (c) => {
105
+ if ((c.kind?.own?.is ?? null) === "VariableDeclaration")
106
+ return !c.location?.nested;
107
+ return c.name != null || c.kind?.parent?.is !== "CallExpression";
108
+ };
109
+ // The edges the file's facts produce — every relation, once.
110
+ const edgesOf = (facts) => Object.values(kinds_1.EDGE_FACTS).flatMap((produce) => produce(facts));
111
+ // The pieces that touch something: a piece that touches nothing needs no role
112
+ // — "nothing is allowed from it" is not a statement about code that does not
113
+ // reach anything. Silence for those is not permission — it is the absence of a
114
+ // question.
115
+ const piecesWithEdges = (edges) => new Set(edges.map((e) => e.piece).filter((p) => Boolean(p)));
116
+ // A piece whose VALUE is judged by the css-fact invariants, not by a role: a
117
+ // styled/createGlobalStyle/css fragment (a tagged template), or a DATA literal
118
+ // (a token group, a breakpoint table, a rhythm origin). These are values, not
119
+ // behaviour — the settled model leaves them unroled on purpose and checks their
120
+ // contents instead (`proper-values`, `proper-naming`, `proper-documentation`).
121
+ const VALUE_INITIALIZERS = new Set(["TaggedTemplateExpression", "ObjectLiteralExpression", "SatisfiesExpression", "AsExpression", "ArrayLiteralExpression", "NoSubstitutionTemplateLiteral"]);
122
+ const governedByValues = (c) => VALUE_INITIALIZERS.has(c.kind?.initializer?.is ?? "");
123
+ // Is this candidate an unroled PIECE that touches something? One piece may be
124
+ // described by two candidates — a `const` holding an arrow is the same code
125
+ // seen twice; when one of them got a role, the piece is described. A piece
126
+ // carrying css TEMPLATES, or whose whole value is DATA, is governed by the
127
+ // css-fact invariants, not by a role.
128
+ const isRoled = (c, roledLines) => Boolean(c.role) || roledLines.has(c.lines?.[0] ?? 1);
129
+ const governedByValuesOrCss = (c) => Boolean(c.css?.templates?.length) || governedByValues(c);
130
+ const unroledPiece = (c, roledLines, touching) => !isRoled(c, roledLines) && isPiece(c) && Boolean(c.name) && touching.has(c.name ?? "") && !governedByValuesOrCss(c);
131
+ // One unroled piece's finding, once per piece.
132
+ const unroledFindings = (withRoles, scene, out) => {
133
+ const roledLines = new Set(withRoles.filter((x) => x.role).map((x) => x.lines?.[0] ?? 1));
134
+ const touching = piecesWithEdges(scene.edges);
135
+ const seenPieces = new Set();
136
+ const pieces = withRoles.filter((c) => unroledPiece(c, roledLines, touching));
137
+ for (const c of pieces) {
138
+ const what = c.name ?? `the anonymous function at line ${c.lines?.[0] ?? 1}`;
139
+ if (!(0, speak_1.speakOnce)(seenPieces, what))
140
+ continue;
141
+ out.push((0, cli_report_1.findingFrom)({ ...noRole(what, c, scene), line: c.lines?.[0] ?? 1 }, "nodes", scene.decl.owner ?? scene.ctx.rel, `unroled:${scene.decl.owner ?? "tree"}:${what}`, { path: scene.ctx.rel, what }));
142
+ }
143
+ return seenPieces.size;
144
+ };
145
+ // A file NOTHING describes: no role present and no piece to say it about (a
146
+ // file of re-exports, a file of imports). Said once, for the file — and only
147
+ // when the file actually does something. A BARREL (every export re-exports
148
+ // another module) holds no code of its own, so it is not a thing to role: its
149
+ // re-exports are governed by `no-re-exports`'s place list, not by a role.
150
+ const reexportOnly = (scene) => {
151
+ const exports = scene.ctx.facts?.exports ?? [];
152
+ return exports.length > 0 && exports.every((entry) => Boolean(entry.from));
153
+ };
154
+ // A file whose every piece is DATA or a style fragment holds no behaviour to
155
+ // role: its values are judged by the css-fact invariants.
156
+ const isValuePiece = (c) => governedByValues(c) || Boolean(c.role) || Boolean(c.css?.templates?.length);
157
+ const onlyValuePieces = (candidates) => candidates.length > 0 && candidates.every(isValuePiece);
158
+ const fileFinding = (scene, out) => {
159
+ if (!scene.edges.some((e) => e.path !== scene.ctx.rel))
160
+ return;
161
+ if (reexportOnly(scene) || onlyValuePieces(scene.ctx.facts?.candidates ?? []))
162
+ return;
163
+ out.push((0, cli_report_1.findingFrom)({ ...noRole(scene.ctx.rel, null, scene) }, "nodes", scene.decl.owner ?? scene.ctx.rel, `unroled:${scene.decl.owner ?? "tree"}:file`, { path: scene.ctx.rel, what: scene.ctx.rel }));
164
+ };
165
+ // The scan view the lookalike question needs: the project, the repo anchor,
166
+ // the aliases, the file list, and the run's similarity cache.
167
+ const similarScanOf = (ctx, arch, project, repoFiles) => ({
168
+ project,
169
+ repoRoot: arch.repoRoot ?? ctx.repoRoot ?? ".",
170
+ aliases: ctx.aliases,
171
+ repoFiles,
172
+ cache: (arch.similarCache ??= { files: new Map() }),
173
+ });
174
+ // The file's facts with the repo list attached — the edge producers' target.
175
+ // The pipeline fills `ctx.facts` before this phase runs; the fallback keeps
176
+ // the producers total for a context that carries none.
177
+ const factsOf = (ctx, repoFiles) => {
178
+ const empty = { lines: [], imports: [], exports: [], location: (0, location_1.placeOf)(ctx.rel), reads: [], kind: { own: { is: "SourceFile" }, descendants: [] }, candidates: [], roles: [] };
179
+ return { ...(ctx.facts ?? empty), repoFiles };
180
+ };
181
+ const checkUnroled = (withRoles, run) => {
182
+ const { present, ctx, arch, project, repoFiles, out } = run;
183
+ const decl = declarationOf(ctx, arch);
184
+ // What this folder LOOKS LIKE, if anything: every declared entity whose shape
185
+ // the folder already satisfies for the threshold or more. No single fallback
186
+ // place — a folder may be 80% a feature and 66% a type home, and both are offered.
187
+ const like = (0, similar_1.similarNodes)(arch, (0, location_1.dirOf)(ctx.rel), similarScanOf(ctx, arch, project, repoFiles));
188
+ const edges = edgesOf(factsOf(ctx, repoFiles));
189
+ const unroled = unroledFindings(withRoles, { ctx, decl, like, edges }, out);
190
+ if (!present.length && !unroled)
191
+ fileFinding({ ctx, decl, like, edges }, out);
192
+ };
193
+ exports.checkUnroled = checkUnroled;
@@ -0,0 +1,7 @@
1
+ import type { Project } from "ts-morph";
2
+ import { createTsProject } from "./entities/ast";
3
+ import type { Arch } from "./entities/architecture";
4
+ import type { Finding } from "./entities/findings";
5
+ import type { SeenStore } from "./utils/seen";
6
+ declare const checkFile: (abs: string, arch: Arch, project: Project, repoFiles: string[], dedupe: SeenStore) => Finding[];
7
+ export { checkFile, createTsProject };
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createTsProject = exports.checkFile = void 0;
4
+ const ast_1 = require("./entities/ast");
5
+ Object.defineProperty(exports, "createTsProject", { enumerable: true, get: function () { return ast_1.createTsProject; } });
6
+ const classify_1 = require("./code-roles/classify");
7
+ const project_1 = require("./code-roles/project");
8
+ const tree_1 = require("./entities/tree");
9
+ const finally_1 = require("./nodes/finally");
10
+ const invariants_1 = require("./invariants");
11
+ const cli_report_1 = require("./report/cli-report");
12
+ const pipeline_facts_1 = require("./pipeline-facts");
13
+ const pipeline_roles_1 = require("./pipeline-roles");
14
+ const pipeline_unroled_1 = require("./pipeline-unroled");
15
+ // Does any filter name the project-wide `codeRole` scope (as a field or a
16
+ // `$codeRole.…` reference)? Only then is the project-wide classify pass worth
17
+ // running — a config that never asks for it pays nothing.
18
+ const filterNamesCodeRole = (filter) => {
19
+ if (typeof filter === "string")
20
+ return filter.includes("$codeRole");
21
+ if (Array.isArray(filter))
22
+ return filter.some(filterNamesCodeRole);
23
+ if (filter === null || typeof filter !== "object")
24
+ return false;
25
+ return Object.entries(filter).some(([key, value]) => key === "codeRole" || filterNamesCodeRole(value));
26
+ };
27
+ const invariantNamesCodeRole = (inv) => inv.when !== null && filterNamesCodeRole(inv.when) ? true : inv.infer.some(filterNamesCodeRole) || inv.children.some(invariantNamesCodeRole);
28
+ const namesCodeRole = (invs) => invs.some(invariantNamesCodeRole);
29
+ // The lazy `codeRole` scope: role slug → the project-wide classified pieces.
30
+ // Defined as a getter so the whole-project scan runs only when a filter reads
31
+ // it, and memoised in the closure so it runs once per file.
32
+ const defineCodeRole = (facts, build) => {
33
+ let cached = null;
34
+ Object.defineProperty(facts, "codeRole", {
35
+ enumerable: true,
36
+ configurable: true,
37
+ get: () => (cached ??= build()),
38
+ });
39
+ };
40
+ const checkFile = (...args) => {
41
+ const [abs, arch, project, repoFiles, dedupe] = args;
42
+ // 1. LOAD → FACTS: candidates once, facets attached, the file's fact set.
43
+ const { ctx, candidates, fileFacts } = (0, pipeline_facts_1.collectFacts)(abs, arch, project, repoFiles, dedupe);
44
+ // 2. ROLES: classify, then fill the two fields that need the classification.
45
+ const { present, roleCtx, candidates: withRoles } = (0, classify_1.classifyRoles)(candidates, arch.codeRoles ?? {}, arch, fileFacts);
46
+ ctx.roles = present;
47
+ ctx.roleCtx = roleCtx;
48
+ // `c.file` is the snapshot every candidate carries, and roles are known only
49
+ // now: filling them here keeps "the file this piece sits in" complete instead
50
+ // of a copy that silently lacks the one field a rule asks about.
51
+ fileFacts.roles = [...new Set(present)];
52
+ // File facts (candidates attached) — the invariants' filter target.
53
+ // `repoFiles` travels with the facts: an edge's module is a repo FILE or a
54
+ // library SPECIFIER, and the file list is the one place that tells them apart.
55
+ ctx.facts = { ...fileFacts, candidates: withRoles, roles: [...new Set(present)], repoFiles };
56
+ // The project-wide role index serves two things, both lazy: the `codeRole`
57
+ // scope a filter can navigate, and the objects resolution resolves against.
58
+ if (namesCodeRole(arch.invariants))
59
+ defineCodeRole(ctx.facts, () => (0, project_1.codeRoleScope)((0, project_1.projectRoleIndex)(project, arch, repoFiles)));
60
+ ctx.objectsFor = (slugs) => (0, project_1.objectsFor)((0, project_1.projectRoleIndex)(project, arch, repoFiles), slugs);
61
+ const out = [];
62
+ // 3. ROLE HOMES: every candidate must fit its role's declared home.
63
+ (0, pipeline_roles_1.checkRoleHomes)(withRoles, ctx, arch, out);
64
+ // 4. UNROLED: the pieces no role describes, and the file nothing describes.
65
+ (0, pipeline_unroled_1.checkUnroled)(withRoles, { present, ctx, arch, project, repoFiles, out });
66
+ // 5. STRUCTURE: the node tree, then the built-in structure rule (kind +
67
+ // declaration), then the invariants.
68
+ (0, tree_1.checkTree)(ctx.rel, arch, out, cli_report_1.findingFrom, ctx.facts, ctx.repoFiles);
69
+ (0, finally_1.checkFinally)(ctx, arch, out, cli_report_1.findingFrom);
70
+ (0, invariants_1.checkInvariants)(arch.invariants, ctx, out, cli_report_1.findingFrom, dedupe);
71
+ return out;
72
+ };
73
+ exports.checkFile = checkFile;