@aiready/context-analyzer 0.22.9 → 0.22.11

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 (302) hide show
  1. package/.turbo/turbo-build.log +33 -32
  2. package/.turbo/turbo-format-check.log +1 -1
  3. package/.turbo/turbo-lint.log +8 -0
  4. package/dist/chunk-HD4Y3GYL.mjs +124 -0
  5. package/dist/{chunk-M2EGQ36M.mjs → chunk-ISWPFG2C.mjs} +43 -98
  6. package/dist/{chunk-BQCISA2F.mjs → chunk-QW6ULRML.mjs} +32 -6
  7. package/dist/{chunk-WHB7QI7N.mjs → chunk-T733LS62.mjs} +23 -4
  8. package/dist/{cli-action-CXIHOVAC.mjs → cli-action-FV4G4OB6.mjs} +3 -3
  9. package/dist/{cli-action-3CWN7PBE.mjs → cli-action-HYSWE7F4.mjs} +3 -3
  10. package/dist/{cli-action-MLFCIW2O.mjs → cli-action-VIQZSWSP.mjs} +3 -3
  11. package/dist/{cli-action-E7UGP4KE.mjs → cli-action-W7TESWAV.mjs} +6 -8
  12. package/dist/cli.js +236 -191
  13. package/dist/cli.mjs +1 -1
  14. package/dist/console-report-AP4JYNQY.mjs +74 -0
  15. package/dist/html-report-ULELSIYG.mjs +73 -0
  16. package/dist/index.d.mts +69 -337
  17. package/dist/index.d.ts +69 -337
  18. package/dist/index.js +90 -452
  19. package/dist/index.mjs +9 -157
  20. package/dist/interactive-setup-JGFBFI3M.mjs +75 -0
  21. package/dist/{orchestrator-3ERQS3NW.mjs → orchestrator-QNE2E4TE.mjs} +2 -2
  22. package/dist/summary-GQRWW3A2.mjs +7 -0
  23. package/dist/summary-JTBS7CPM.mjs +7 -0
  24. package/dist/summary-TZFB6ZFM.mjs +7 -0
  25. package/package.json +2 -2
  26. package/src/__tests__/file-classification.fixtures.ts +57 -0
  27. package/src/__tests__/file-classification.test.ts +24 -929
  28. package/src/__tests__/provider.test.ts +6 -72
  29. package/src/classifier.ts +42 -42
  30. package/src/cli-action.ts +11 -6
  31. package/src/index.ts +30 -27
  32. package/src/provider.ts +1 -1
  33. package/src/summary.ts +65 -10
  34. package/dist/__tests__/analyzer.test.d.ts +0 -2
  35. package/dist/__tests__/analyzer.test.d.ts.map +0 -1
  36. package/dist/__tests__/analyzer.test.js +0 -198
  37. package/dist/__tests__/analyzer.test.js.map +0 -1
  38. package/dist/__tests__/auto-detection.test.d.ts +0 -2
  39. package/dist/__tests__/auto-detection.test.d.ts.map +0 -1
  40. package/dist/__tests__/auto-detection.test.js +0 -132
  41. package/dist/__tests__/auto-detection.test.js.map +0 -1
  42. package/dist/__tests__/cluster-detector.test.d.ts +0 -2
  43. package/dist/__tests__/cluster-detector.test.d.ts.map +0 -1
  44. package/dist/__tests__/cluster-detector.test.js +0 -121
  45. package/dist/__tests__/cluster-detector.test.js.map +0 -1
  46. package/dist/__tests__/contract.test.d.ts +0 -2
  47. package/dist/__tests__/contract.test.d.ts.map +0 -1
  48. package/dist/__tests__/contract.test.js +0 -59
  49. package/dist/__tests__/contract.test.js.map +0 -1
  50. package/dist/__tests__/enhanced-cohesion.test.d.ts +0 -2
  51. package/dist/__tests__/enhanced-cohesion.test.d.ts.map +0 -1
  52. package/dist/__tests__/enhanced-cohesion.test.js +0 -119
  53. package/dist/__tests__/enhanced-cohesion.test.js.map +0 -1
  54. package/dist/__tests__/file-classification.test.d.ts +0 -2
  55. package/dist/__tests__/file-classification.test.d.ts.map +0 -1
  56. package/dist/__tests__/file-classification.test.js +0 -749
  57. package/dist/__tests__/file-classification.test.js.map +0 -1
  58. package/dist/__tests__/fragmentation-advanced.test.d.ts +0 -2
  59. package/dist/__tests__/fragmentation-advanced.test.d.ts.map +0 -1
  60. package/dist/__tests__/fragmentation-advanced.test.js +0 -44
  61. package/dist/__tests__/fragmentation-advanced.test.js.map +0 -1
  62. package/dist/__tests__/fragmentation-coupling.test.d.ts +0 -2
  63. package/dist/__tests__/fragmentation-coupling.test.d.ts.map +0 -1
  64. package/dist/__tests__/fragmentation-coupling.test.js +0 -52
  65. package/dist/__tests__/fragmentation-coupling.test.js.map +0 -1
  66. package/dist/__tests__/fragmentation-log.test.d.ts +0 -2
  67. package/dist/__tests__/fragmentation-log.test.d.ts.map +0 -1
  68. package/dist/__tests__/fragmentation-log.test.js +0 -29
  69. package/dist/__tests__/fragmentation-log.test.js.map +0 -1
  70. package/dist/__tests__/provider.test.d.ts +0 -2
  71. package/dist/__tests__/provider.test.d.ts.map +0 -1
  72. package/dist/__tests__/provider.test.js +0 -72
  73. package/dist/__tests__/provider.test.js.map +0 -1
  74. package/dist/__tests__/remediation.test.d.ts +0 -2
  75. package/dist/__tests__/remediation.test.d.ts.map +0 -1
  76. package/dist/__tests__/remediation.test.js +0 -61
  77. package/dist/__tests__/remediation.test.js.map +0 -1
  78. package/dist/__tests__/scoring.test.d.ts +0 -2
  79. package/dist/__tests__/scoring.test.d.ts.map +0 -1
  80. package/dist/__tests__/scoring.test.js +0 -298
  81. package/dist/__tests__/scoring.test.js.map +0 -1
  82. package/dist/__tests__/structural-cohesion.test.d.ts +0 -2
  83. package/dist/__tests__/structural-cohesion.test.d.ts.map +0 -1
  84. package/dist/__tests__/structural-cohesion.test.js +0 -35
  85. package/dist/__tests__/structural-cohesion.test.js.map +0 -1
  86. package/dist/analyzer.d.ts +0 -37
  87. package/dist/analyzer.d.ts.map +0 -1
  88. package/dist/analyzer.js +0 -283
  89. package/dist/analyzer.js.map +0 -1
  90. package/dist/analyzers/python-context.d.ts +0 -38
  91. package/dist/analyzers/python-context.d.ts.map +0 -1
  92. package/dist/analyzers/python-context.js +0 -234
  93. package/dist/analyzers/python-context.js.map +0 -1
  94. package/dist/ast-utils.d.ts +0 -16
  95. package/dist/ast-utils.d.ts.map +0 -1
  96. package/dist/ast-utils.js +0 -81
  97. package/dist/ast-utils.js.map +0 -1
  98. package/dist/chunk-22ZO4EKZ.mjs +0 -1297
  99. package/dist/chunk-2HE27YEV.mjs +0 -1739
  100. package/dist/chunk-45P4RDYP.mjs +0 -607
  101. package/dist/chunk-474DEGWW.mjs +0 -1792
  102. package/dist/chunk-4SYIJ7CU.mjs +0 -1538
  103. package/dist/chunk-4U4LDWGF.mjs +0 -360
  104. package/dist/chunk-4XQVYYPC.mjs +0 -1470
  105. package/dist/chunk-5CLU3HYU.mjs +0 -1475
  106. package/dist/chunk-5K73Q3OQ.mjs +0 -1520
  107. package/dist/chunk-5N5DCJOV.mjs +0 -583
  108. package/dist/chunk-6AVS4KTM.mjs +0 -1536
  109. package/dist/chunk-6FQYIG6I.mjs +0 -1298
  110. package/dist/chunk-6I4552YB.mjs +0 -1467
  111. package/dist/chunk-6LPITDKG.mjs +0 -1539
  112. package/dist/chunk-72QC5QUS.mjs +0 -549
  113. package/dist/chunk-736QSHJP.mjs +0 -1807
  114. package/dist/chunk-7LUSCLGR.mjs +0 -2058
  115. package/dist/chunk-7VK3XTSH.mjs +0 -1756
  116. package/dist/chunk-7ZEJGWLN.mjs +0 -1363
  117. package/dist/chunk-AECWO7NQ.mjs +0 -1539
  118. package/dist/chunk-AEK3MZC5.mjs +0 -709
  119. package/dist/chunk-AJC3FR6G.mjs +0 -1509
  120. package/dist/chunk-AMPK6SWS.mjs +0 -1754
  121. package/dist/chunk-BA7QGUHN.mjs +0 -1722
  122. package/dist/chunk-BCEZGRXI.mjs +0 -1297
  123. package/dist/chunk-BD4NWUVG.mjs +0 -1242
  124. package/dist/chunk-BEZPBI5C.mjs +0 -1829
  125. package/dist/chunk-BHCRDEE4.mjs +0 -1745
  126. package/dist/chunk-BW463GQB.mjs +0 -1767
  127. package/dist/chunk-CAX2MOUZ.mjs +0 -1801
  128. package/dist/chunk-CBWM3EK5.mjs +0 -1854
  129. package/dist/chunk-CCBNKQYB.mjs +0 -1812
  130. package/dist/chunk-CDIVYADN.mjs +0 -2110
  131. package/dist/chunk-CVGIDSMN.mjs +0 -1522
  132. package/dist/chunk-D25B5LZR.mjs +0 -1739
  133. package/dist/chunk-D3SIHB2V.mjs +0 -2118
  134. package/dist/chunk-DD7UVNE3.mjs +0 -678
  135. package/dist/chunk-DMRZMS2U.mjs +0 -964
  136. package/dist/chunk-DXG5NIYL.mjs +0 -1527
  137. package/dist/chunk-EBXG2Q5Y.mjs +0 -2059
  138. package/dist/chunk-EH3PMNZQ.mjs +0 -569
  139. package/dist/chunk-EMYD7NS6.mjs +0 -137
  140. package/dist/chunk-EVX2W2BK.mjs +0 -1896
  141. package/dist/chunk-EWFR366Y.mjs +0 -1740
  142. package/dist/chunk-EX7HCWAO.mjs +0 -625
  143. package/dist/chunk-FNPSK3CG.mjs +0 -1760
  144. package/dist/chunk-FO6YT6RG.mjs +0 -1751
  145. package/dist/chunk-FYI56A5M.mjs +0 -1892
  146. package/dist/chunk-G3CCJCBI.mjs +0 -1521
  147. package/dist/chunk-G7PO3DNK.mjs +0 -1072
  148. package/dist/chunk-GFADGYXZ.mjs +0 -1752
  149. package/dist/chunk-GTRIBVS6.mjs +0 -1467
  150. package/dist/chunk-GXTGOLZT.mjs +0 -92
  151. package/dist/chunk-H4HWBQU6.mjs +0 -1530
  152. package/dist/chunk-HDFXSEFW.mjs +0 -605
  153. package/dist/chunk-HOUDVRG2.mjs +0 -1422
  154. package/dist/chunk-HQNHM2X7.mjs +0 -997
  155. package/dist/chunk-I54HL4FZ.mjs +0 -781
  156. package/dist/chunk-I77HFFZU.mjs +0 -1876
  157. package/dist/chunk-IKRP7ECY.mjs +0 -1754
  158. package/dist/chunk-ILMLGJGI.mjs +0 -1295
  159. package/dist/chunk-IPIE5TXJ.mjs +0 -1741
  160. package/dist/chunk-IRWCPDWD.mjs +0 -779
  161. package/dist/chunk-J3MUOWHC.mjs +0 -1747
  162. package/dist/chunk-J5TA3AZU.mjs +0 -1795
  163. package/dist/chunk-JH535NPP.mjs +0 -1619
  164. package/dist/chunk-JUHHOSHG.mjs +0 -1808
  165. package/dist/chunk-JZ2SE4DB.mjs +0 -1116
  166. package/dist/chunk-K2WFOBAZ.mjs +0 -1821
  167. package/dist/chunk-K6U64EL3.mjs +0 -517
  168. package/dist/chunk-KDUUZQBK.mjs +0 -1692
  169. package/dist/chunk-KGFWKSGJ.mjs +0 -1442
  170. package/dist/chunk-KGVMS4R5.mjs +0 -1750
  171. package/dist/chunk-KWIS5FQP.mjs +0 -1739
  172. package/dist/chunk-KYSZF5N6.mjs +0 -1876
  173. package/dist/chunk-LERPI33Y.mjs +0 -2060
  174. package/dist/chunk-M64RHH4D.mjs +0 -1896
  175. package/dist/chunk-MBE4AQP5.mjs +0 -1362
  176. package/dist/chunk-MR7WXHIE.mjs +0 -1833
  177. package/dist/chunk-MZP3G7TF.mjs +0 -2118
  178. package/dist/chunk-N2GQWNFG.mjs +0 -1527
  179. package/dist/chunk-N6XBOOVA.mjs +0 -564
  180. package/dist/chunk-NJUW6VED.mjs +0 -610
  181. package/dist/chunk-NOHK5DLU.mjs +0 -2173
  182. package/dist/chunk-NQA3F2HJ.mjs +0 -1532
  183. package/dist/chunk-NXXQ2U73.mjs +0 -1467
  184. package/dist/chunk-OP4G6GLN.mjs +0 -1876
  185. package/dist/chunk-ORLC5Y4J.mjs +0 -1787
  186. package/dist/chunk-OTCQL7DY.mjs +0 -2045
  187. package/dist/chunk-OUYSZZ7X.mjs +0 -1846
  188. package/dist/chunk-OZE3FVZT.mjs +0 -1089
  189. package/dist/chunk-P3T3H27S.mjs +0 -1895
  190. package/dist/chunk-P5YV5WIX.mjs +0 -1803
  191. package/dist/chunk-P74BO725.mjs +0 -1296
  192. package/dist/chunk-PDN74MG3.mjs +0 -1834
  193. package/dist/chunk-PJD4VCIH.mjs +0 -1722
  194. package/dist/chunk-PVVCCE6W.mjs +0 -755
  195. package/dist/chunk-PVVMK56C.mjs +0 -1793
  196. package/dist/chunk-Q2GDZ2FZ.mjs +0 -1794
  197. package/dist/chunk-QDGPR3L6.mjs +0 -1518
  198. package/dist/chunk-RQCIJO5Z.mjs +0 -1116
  199. package/dist/chunk-RRB2C34Q.mjs +0 -1738
  200. package/dist/chunk-RYIB5CWD.mjs +0 -781
  201. package/dist/chunk-S6OPP4L5.mjs +0 -1791
  202. package/dist/chunk-SAVOSPM3.mjs +0 -1522
  203. package/dist/chunk-SFK6XTJE.mjs +0 -2110
  204. package/dist/chunk-SIX4KMF2.mjs +0 -1468
  205. package/dist/chunk-SPAM2YJE.mjs +0 -1537
  206. package/dist/chunk-T6ZCOPPI.mjs +0 -538
  207. package/dist/chunk-TPF75CNP.mjs +0 -581
  208. package/dist/chunk-TWWPY7FD.mjs +0 -1754
  209. package/dist/chunk-U5R2FTCR.mjs +0 -1803
  210. package/dist/chunk-UG7OPVHB.mjs +0 -1521
  211. package/dist/chunk-UMZTAWDA.mjs +0 -1812
  212. package/dist/chunk-UU4HZ7ZT.mjs +0 -1849
  213. package/dist/chunk-UXC6QUZ7.mjs +0 -1801
  214. package/dist/chunk-VBWXHKGD.mjs +0 -1895
  215. package/dist/chunk-VIJTZPBI.mjs +0 -1470
  216. package/dist/chunk-VLV6MXPL.mjs +0 -1750
  217. package/dist/chunk-VTALAPQZ.mjs +0 -1241
  218. package/dist/chunk-W2KNBN6W.mjs +0 -1849
  219. package/dist/chunk-W37E7MW5.mjs +0 -1403
  220. package/dist/chunk-W76FEISE.mjs +0 -1538
  221. package/dist/chunk-WCFQYXQA.mjs +0 -1532
  222. package/dist/chunk-WKOZOHOU.mjs +0 -2060
  223. package/dist/chunk-WTQJNY4U.mjs +0 -1785
  224. package/dist/chunk-XBFM2Z4O.mjs +0 -1792
  225. package/dist/chunk-XIXAWCMS.mjs +0 -1760
  226. package/dist/chunk-XTAXUNQN.mjs +0 -1742
  227. package/dist/chunk-XY77XABG.mjs +0 -1545
  228. package/dist/chunk-XZ645X5U.mjs +0 -1425
  229. package/dist/chunk-Y6FXYEAI.mjs +0 -10
  230. package/dist/chunk-YCGDIGOG.mjs +0 -1467
  231. package/dist/chunk-YYB6NZE3.mjs +0 -1869
  232. package/dist/chunk-Z5WY6A4P.mjs +0 -1754
  233. package/dist/chunk-ZAMFWKIB.mjs +0 -1842
  234. package/dist/classifier.d.ts +0 -114
  235. package/dist/classifier.d.ts.map +0 -1
  236. package/dist/classifier.js +0 -439
  237. package/dist/classifier.js.map +0 -1
  238. package/dist/cli-action-SA7SCYNV.mjs +0 -95
  239. package/dist/cli-action-VCXBZGZP.mjs +0 -95
  240. package/dist/cli-action-YAJOJCXJ.mjs +0 -95
  241. package/dist/cli.d.ts.map +0 -1
  242. package/dist/cli.js.map +0 -1
  243. package/dist/cluster-detector.d.ts +0 -8
  244. package/dist/cluster-detector.d.ts.map +0 -1
  245. package/dist/cluster-detector.js +0 -70
  246. package/dist/cluster-detector.js.map +0 -1
  247. package/dist/defaults.d.ts +0 -7
  248. package/dist/defaults.d.ts.map +0 -1
  249. package/dist/defaults.js +0 -54
  250. package/dist/defaults.js.map +0 -1
  251. package/dist/graph-builder.d.ts +0 -33
  252. package/dist/graph-builder.d.ts.map +0 -1
  253. package/dist/graph-builder.js +0 -225
  254. package/dist/graph-builder.js.map +0 -1
  255. package/dist/index.d.ts.map +0 -1
  256. package/dist/index.js.map +0 -1
  257. package/dist/metrics.d.ts +0 -34
  258. package/dist/metrics.d.ts.map +0 -1
  259. package/dist/metrics.js +0 -170
  260. package/dist/metrics.js.map +0 -1
  261. package/dist/orchestrator-3L3NAZYP.mjs +0 -10
  262. package/dist/orchestrator-5AL3XBPZ.mjs +0 -10
  263. package/dist/orchestrator-KMAKMHTD.mjs +0 -10
  264. package/dist/orchestrator-MONOZHVW.mjs +0 -10
  265. package/dist/orchestrator-R6MZT4Z2.mjs +0 -10
  266. package/dist/orchestrator-ZR7JSKWI.mjs +0 -10
  267. package/dist/provider.d.ts +0 -6
  268. package/dist/provider.d.ts.map +0 -1
  269. package/dist/provider.js +0 -48
  270. package/dist/provider.js.map +0 -1
  271. package/dist/python-context-3GZKN3LR.mjs +0 -162
  272. package/dist/python-context-GOH747QU.mjs +0 -202
  273. package/dist/python-context-O2EN3M6Z.mjs +0 -162
  274. package/dist/python-context-PAETRLDY.mjs +0 -185
  275. package/dist/python-context-TBI5FVFY.mjs +0 -203
  276. package/dist/python-context-UOPTQH44.mjs +0 -192
  277. package/dist/remediation.d.ts +0 -25
  278. package/dist/remediation.d.ts.map +0 -1
  279. package/dist/remediation.js +0 -98
  280. package/dist/remediation.js.map +0 -1
  281. package/dist/scoring.d.ts +0 -9
  282. package/dist/scoring.d.ts.map +0 -1
  283. package/dist/scoring.js +0 -142
  284. package/dist/scoring.js.map +0 -1
  285. package/dist/semantic-analysis.d.ts +0 -33
  286. package/dist/semantic-analysis.d.ts.map +0 -1
  287. package/dist/semantic-analysis.js +0 -303
  288. package/dist/semantic-analysis.js.map +0 -1
  289. package/dist/summary-7PZVW72O.mjs +0 -7
  290. package/dist/summary-LKUCJAIS.mjs +0 -7
  291. package/dist/summary.d.ts +0 -6
  292. package/dist/summary.d.ts.map +0 -1
  293. package/dist/summary.js +0 -92
  294. package/dist/summary.js.map +0 -1
  295. package/dist/types.d.ts +0 -124
  296. package/dist/types.d.ts.map +0 -1
  297. package/dist/types.js +0 -2
  298. package/dist/types.js.map +0 -1
  299. package/dist/utils/output-formatter.d.ts +0 -14
  300. package/dist/utils/output-formatter.d.ts.map +0 -1
  301. package/dist/utils/output-formatter.js +0 -338
  302. package/dist/utils/output-formatter.js.map +0 -1
@@ -1,360 +0,0 @@
1
- // src/utils/string-utils.ts
2
- function singularize(word) {
3
- const irregulars = {
4
- people: "person",
5
- children: "child",
6
- men: "man",
7
- women: "woman"
8
- };
9
- if (irregulars[word]) return irregulars[word];
10
- if (word.endsWith("ies")) return word.slice(0, -3) + "y";
11
- if (word.endsWith("ses")) return word.slice(0, -2);
12
- if (word.endsWith("s") && word.length > 3) return word.slice(0, -1);
13
- return word;
14
- }
15
-
16
- // src/semantic/domain-inference.ts
17
- function calculateDomainConfidence(signals) {
18
- const weights = {
19
- coUsage: 0.35,
20
- typeReference: 0.3,
21
- exportName: 0.15,
22
- importPath: 0.1,
23
- folderStructure: 0.1
24
- };
25
- let confidence = 0;
26
- if (signals.coUsage) confidence += weights.coUsage;
27
- if (signals.typeReference) confidence += weights.typeReference;
28
- if (signals.exportName) confidence += weights.exportName;
29
- if (signals.importPath) confidence += weights.importPath;
30
- if (signals.folderStructure) confidence += weights.folderStructure;
31
- return confidence;
32
- }
33
- function inferDomainFromSemantics(file, exportName, graph, coUsageMatrix, typeGraph, exportTypeRefs) {
34
- const domainSignals = /* @__PURE__ */ new Map();
35
- const coUsages = coUsageMatrix.get(file) || /* @__PURE__ */ new Map();
36
- const strongCoUsages = Array.from(coUsages.entries()).filter(([, count]) => count >= 3).map(([coFile]) => coFile);
37
- for (const coFile of strongCoUsages) {
38
- const coNode = graph.nodes.get(coFile);
39
- if (coNode) {
40
- for (const exp of coNode.exports) {
41
- if (exp.inferredDomain && exp.inferredDomain !== "unknown") {
42
- const domain = exp.inferredDomain;
43
- if (!domainSignals.has(domain)) {
44
- domainSignals.set(domain, {
45
- coUsage: false,
46
- typeReference: false,
47
- exportName: false,
48
- importPath: false,
49
- folderStructure: false
50
- });
51
- }
52
- domainSignals.get(domain).coUsage = true;
53
- }
54
- }
55
- }
56
- }
57
- if (exportTypeRefs) {
58
- for (const typeRef of exportTypeRefs) {
59
- const filesWithType = typeGraph.get(typeRef);
60
- if (filesWithType) {
61
- for (const typeFile of filesWithType) {
62
- if (typeFile === file) continue;
63
- const typeNode = graph.nodes.get(typeFile);
64
- if (typeNode) {
65
- for (const exp of typeNode.exports) {
66
- if (exp.inferredDomain && exp.inferredDomain !== "unknown") {
67
- const domain = exp.inferredDomain;
68
- if (!domainSignals.has(domain)) {
69
- domainSignals.set(domain, {
70
- coUsage: false,
71
- typeReference: false,
72
- exportName: false,
73
- importPath: false,
74
- folderStructure: false
75
- });
76
- }
77
- domainSignals.get(domain).typeReference = true;
78
- }
79
- }
80
- }
81
- }
82
- }
83
- }
84
- }
85
- const assignments = [];
86
- for (const [domain, signals] of domainSignals) {
87
- const confidence = calculateDomainConfidence(signals);
88
- if (confidence >= 0.3) assignments.push({ domain, confidence, signals });
89
- }
90
- assignments.sort((a, b) => b.confidence - a.confidence);
91
- return assignments;
92
- }
93
- function extractExports(content, filePath, domainOptions, fileImports) {
94
- const exports = [];
95
- const patterns = [
96
- /export\s+function\s+(\w+)/g,
97
- /export\s+class\s+(\w+)/g,
98
- /export\s+const\s+(\w+)/g,
99
- /export\s+type\s+(\w+)/g,
100
- /export\s+interface\s+(\w+)/g,
101
- /export\s+default/g
102
- ];
103
- const types = [
104
- "function",
105
- "class",
106
- "const",
107
- "type",
108
- "interface",
109
- "default"
110
- ];
111
- patterns.forEach((pattern, index) => {
112
- let match;
113
- while ((match = pattern.exec(content)) !== null) {
114
- const name = match[1] || "default";
115
- const type = types[index];
116
- const inferredDomain = inferDomain(
117
- name,
118
- filePath,
119
- domainOptions,
120
- fileImports
121
- );
122
- exports.push({ name, type, inferredDomain });
123
- }
124
- });
125
- return exports;
126
- }
127
- function inferDomain(name, filePath, domainOptions, fileImports) {
128
- const lower = name.toLowerCase();
129
- const tokens = Array.from(
130
- new Set(
131
- lower.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[^a-z0-9]+/gi, " ").split(" ").filter(Boolean)
132
- )
133
- );
134
- const defaultKeywords = [
135
- "authentication",
136
- "authorization",
137
- "payment",
138
- "invoice",
139
- "customer",
140
- "product",
141
- "order",
142
- "cart",
143
- "user",
144
- "admin",
145
- "repository",
146
- "controller",
147
- "service",
148
- "config",
149
- "model",
150
- "view",
151
- "auth"
152
- ];
153
- const domainKeywords = domainOptions?.domainKeywords?.length ? [...domainOptions.domainKeywords, ...defaultKeywords] : defaultKeywords;
154
- for (const keyword of domainKeywords) {
155
- if (tokens.includes(keyword)) return keyword;
156
- }
157
- for (const keyword of domainKeywords) {
158
- if (lower.includes(keyword)) return keyword;
159
- }
160
- if (fileImports) {
161
- for (const importPath of fileImports) {
162
- const segments = importPath.split("/");
163
- for (const segment of segments) {
164
- const segLower = segment.toLowerCase();
165
- const singularSegment = singularize(segLower);
166
- for (const keyword of domainKeywords) {
167
- if (singularSegment === keyword || segLower === keyword || segLower.includes(keyword))
168
- return keyword;
169
- }
170
- }
171
- }
172
- }
173
- if (filePath) {
174
- const segments = filePath.split("/");
175
- for (const segment of segments) {
176
- const segLower = segment.toLowerCase();
177
- const singularSegment = singularize(segLower);
178
- for (const keyword of domainKeywords) {
179
- if (singularSegment === keyword || segLower === keyword) return keyword;
180
- }
181
- }
182
- }
183
- return "unknown";
184
- }
185
-
186
- // src/metrics.ts
187
- import { calculateImportSimilarity } from "@aiready/core";
188
-
189
- // src/ast-utils.ts
190
- import { parseFileExports } from "@aiready/core";
191
- async function extractExportsWithAST(content, filePath, domainOptions, fileImports) {
192
- try {
193
- const { exports: astExports } = await parseFileExports(content, filePath);
194
- if (astExports.length === 0 && !isTestFile(filePath)) {
195
- return extractExports(content, filePath, domainOptions, fileImports);
196
- }
197
- return astExports.map((exp) => ({
198
- name: exp.name,
199
- type: exp.type,
200
- inferredDomain: inferDomain(
201
- exp.name,
202
- filePath,
203
- domainOptions,
204
- fileImports
205
- ),
206
- imports: exp.imports,
207
- dependencies: exp.dependencies,
208
- typeReferences: exp.typeReferences
209
- }));
210
- } catch {
211
- return extractExports(content, filePath, domainOptions, fileImports);
212
- }
213
- }
214
- function isTestFile(filePath) {
215
- const lower = filePath.toLowerCase();
216
- return lower.includes(".test.") || lower.includes(".spec.") || lower.includes("/__tests__/") || lower.includes("/tests/") || lower.includes("/test/") || lower.includes("test-") || lower.includes("-test") || lower.includes("/__mocks__/") || lower.includes("/mocks/") || lower.includes("/fixtures/") || lower.includes(".mock.") || lower.includes(".fixture.") || lower.includes("/test-utils/");
217
- }
218
-
219
- // src/metrics.ts
220
- function calculateEnhancedCohesion(exports, filePath, options) {
221
- if (exports.length <= 1) return 1;
222
- if (filePath && isTestFile(filePath)) return 1;
223
- const domains = exports.map((e) => e.inferredDomain || "unknown");
224
- const domainCounts = /* @__PURE__ */ new Map();
225
- for (const domain of domains)
226
- domainCounts.set(domain, (domainCounts.get(domain) || 0) + 1);
227
- if (domainCounts.size === 1 && domains[0] !== "unknown") {
228
- if (!options?.weights) return 1;
229
- }
230
- const probs = Array.from(domainCounts.values()).map(
231
- (count) => count / exports.length
232
- );
233
- let domainEntropy = 0;
234
- for (const prob of probs) {
235
- if (prob > 0) domainEntropy -= prob * Math.log2(prob);
236
- }
237
- const maxEntropy = Math.log2(Math.max(2, domainCounts.size));
238
- const domainScore = 1 - domainEntropy / maxEntropy;
239
- let importScoreTotal = 0;
240
- let pairsWithData = 0;
241
- let anyImportData = false;
242
- for (let i = 0; i < exports.length; i++) {
243
- for (let j = i + 1; j < exports.length; j++) {
244
- const exp1Imports = exports[i].imports;
245
- const exp2Imports = exports[j].imports;
246
- if (exp1Imports || exp2Imports) {
247
- anyImportData = true;
248
- const sim = calculateImportSimilarity(
249
- { ...exports[i], imports: exp1Imports || [] },
250
- { ...exports[j], imports: exp2Imports || [] }
251
- );
252
- importScoreTotal += sim;
253
- pairsWithData++;
254
- }
255
- }
256
- }
257
- const avgImportScore = pairsWithData > 0 ? importScoreTotal / pairsWithData : 0;
258
- let score = anyImportData ? domainScore * 0.4 + avgImportScore * 0.6 : domainScore;
259
- if (anyImportData && score === 0 && domainScore === 0) {
260
- score = 0.1;
261
- }
262
- let structuralScore = 0;
263
- for (const exp of exports) {
264
- if (exp.dependencies && exp.dependencies.length > 0) {
265
- structuralScore += 1;
266
- }
267
- }
268
- if (structuralScore > 0) {
269
- score = Math.min(1, score + 0.1);
270
- }
271
- if (!options?.weights && !anyImportData && domainCounts.size === 1) return 1;
272
- return score;
273
- }
274
- function calculateStructuralCohesionFromCoUsage(file, coUsageMatrix) {
275
- if (!coUsageMatrix) return 1;
276
- const coUsages = coUsageMatrix.get(file);
277
- if (!coUsages || coUsages.size === 0) return 1;
278
- let total = 0;
279
- for (const count of coUsages.values()) total += count;
280
- if (total === 0) return 1;
281
- const probs = [];
282
- for (const count of coUsages.values()) {
283
- if (count > 0) probs.push(count / total);
284
- }
285
- if (probs.length <= 1) return 1;
286
- let entropy = 0;
287
- for (const prob of probs) {
288
- entropy -= prob * Math.log2(prob);
289
- }
290
- const maxEntropy = Math.log2(probs.length);
291
- return maxEntropy > 0 ? 1 - entropy / maxEntropy : 1;
292
- }
293
- function calculateFragmentation(files, domain, options) {
294
- if (files.length <= 1) return 0;
295
- const directories = new Set(
296
- files.map((file) => file.split("/").slice(0, -1).join("/"))
297
- );
298
- const uniqueDirs = directories.size;
299
- let score = options?.useLogScale ? uniqueDirs <= 1 ? 0 : Math.log(uniqueDirs) / Math.log(options.logBase || Math.E) / (Math.log(files.length) / Math.log(options.logBase || Math.E)) : (uniqueDirs - 1) / (files.length - 1);
300
- if (options?.sharedImportRatio && options.sharedImportRatio > 0.5) {
301
- const discount = (options.sharedImportRatio - 0.5) * 0.4;
302
- score = score * (1 - discount);
303
- }
304
- return score;
305
- }
306
- function calculatePathEntropy(files) {
307
- if (!files || files.length === 0) return 0;
308
- const dirCounts = /* @__PURE__ */ new Map();
309
- for (const file of files) {
310
- const dir = file.split("/").slice(0, -1).join("/") || ".";
311
- dirCounts.set(dir, (dirCounts.get(dir) || 0) + 1);
312
- }
313
- const counts = Array.from(dirCounts.values());
314
- if (counts.length <= 1) return 0;
315
- const total = counts.reduce((sum, value) => sum + value, 0);
316
- let entropy = 0;
317
- for (const count of counts) {
318
- const prob = count / total;
319
- entropy -= prob * Math.log2(prob);
320
- }
321
- const maxEntropy = Math.log2(counts.length);
322
- return maxEntropy > 0 ? entropy / maxEntropy : 0;
323
- }
324
- function calculateDirectoryDistance(files) {
325
- if (!files || files.length <= 1) return 0;
326
- const pathSegments = (pathStr) => pathStr.split("/").filter(Boolean);
327
- const commonAncestorDepth = (pathA, pathB) => {
328
- const minLen = Math.min(pathA.length, pathB.length);
329
- let i = 0;
330
- while (i < minLen && pathA[i] === pathB[i]) i++;
331
- return i;
332
- };
333
- let totalNormalized = 0;
334
- let comparisons = 0;
335
- for (let i = 0; i < files.length; i++) {
336
- for (let j = i + 1; j < files.length; j++) {
337
- const segA = pathSegments(files[i]);
338
- const segB = pathSegments(files[j]);
339
- const shared = commonAncestorDepth(segA, segB);
340
- const maxDepth = Math.max(segA.length, segB.length);
341
- totalNormalized += 1 - (maxDepth > 0 ? shared / maxDepth : 0);
342
- comparisons++;
343
- }
344
- }
345
- return comparisons > 0 ? totalNormalized / comparisons : 0;
346
- }
347
-
348
- export {
349
- singularize,
350
- calculateDomainConfidence,
351
- inferDomainFromSemantics,
352
- extractExports,
353
- inferDomain,
354
- extractExportsWithAST,
355
- calculateEnhancedCohesion,
356
- calculateStructuralCohesionFromCoUsage,
357
- calculateFragmentation,
358
- calculatePathEntropy,
359
- calculateDirectoryDistance
360
- };