@aiready/context-analyzer 0.22.8 → 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 (304) hide show
  1. package/.turbo/turbo-build.log +33 -32
  2. package/.turbo/turbo-format-check.log +2 -2
  3. package/.turbo/turbo-lint.log +9 -1
  4. package/.turbo/turbo-test.log +23 -23
  5. package/.turbo/turbo-type-check.log +1 -1
  6. package/dist/chunk-HD4Y3GYL.mjs +124 -0
  7. package/dist/{chunk-M2EGQ36M.mjs → chunk-ISWPFG2C.mjs} +43 -98
  8. package/dist/{chunk-BQCISA2F.mjs → chunk-QW6ULRML.mjs} +32 -6
  9. package/dist/{chunk-WHB7QI7N.mjs → chunk-T733LS62.mjs} +23 -4
  10. package/dist/{cli-action-CXIHOVAC.mjs → cli-action-FV4G4OB6.mjs} +3 -3
  11. package/dist/{cli-action-3CWN7PBE.mjs → cli-action-HYSWE7F4.mjs} +3 -3
  12. package/dist/{cli-action-MLFCIW2O.mjs → cli-action-VIQZSWSP.mjs} +3 -3
  13. package/dist/{cli-action-E7UGP4KE.mjs → cli-action-W7TESWAV.mjs} +6 -8
  14. package/dist/cli.js +236 -191
  15. package/dist/cli.mjs +1 -1
  16. package/dist/console-report-AP4JYNQY.mjs +74 -0
  17. package/dist/html-report-ULELSIYG.mjs +73 -0
  18. package/dist/index.d.mts +69 -337
  19. package/dist/index.d.ts +69 -337
  20. package/dist/index.js +90 -452
  21. package/dist/index.mjs +9 -157
  22. package/dist/interactive-setup-JGFBFI3M.mjs +75 -0
  23. package/dist/{orchestrator-3ERQS3NW.mjs → orchestrator-QNE2E4TE.mjs} +2 -2
  24. package/dist/summary-GQRWW3A2.mjs +7 -0
  25. package/dist/summary-JTBS7CPM.mjs +7 -0
  26. package/dist/summary-TZFB6ZFM.mjs +7 -0
  27. package/package.json +2 -2
  28. package/src/__tests__/file-classification.fixtures.ts +57 -0
  29. package/src/__tests__/file-classification.test.ts +24 -929
  30. package/src/__tests__/provider.test.ts +6 -72
  31. package/src/classifier.ts +42 -42
  32. package/src/cli-action.ts +11 -6
  33. package/src/index.ts +30 -27
  34. package/src/provider.ts +1 -1
  35. package/src/summary.ts +65 -10
  36. package/dist/__tests__/analyzer.test.d.ts +0 -2
  37. package/dist/__tests__/analyzer.test.d.ts.map +0 -1
  38. package/dist/__tests__/analyzer.test.js +0 -198
  39. package/dist/__tests__/analyzer.test.js.map +0 -1
  40. package/dist/__tests__/auto-detection.test.d.ts +0 -2
  41. package/dist/__tests__/auto-detection.test.d.ts.map +0 -1
  42. package/dist/__tests__/auto-detection.test.js +0 -132
  43. package/dist/__tests__/auto-detection.test.js.map +0 -1
  44. package/dist/__tests__/cluster-detector.test.d.ts +0 -2
  45. package/dist/__tests__/cluster-detector.test.d.ts.map +0 -1
  46. package/dist/__tests__/cluster-detector.test.js +0 -121
  47. package/dist/__tests__/cluster-detector.test.js.map +0 -1
  48. package/dist/__tests__/contract.test.d.ts +0 -2
  49. package/dist/__tests__/contract.test.d.ts.map +0 -1
  50. package/dist/__tests__/contract.test.js +0 -59
  51. package/dist/__tests__/contract.test.js.map +0 -1
  52. package/dist/__tests__/enhanced-cohesion.test.d.ts +0 -2
  53. package/dist/__tests__/enhanced-cohesion.test.d.ts.map +0 -1
  54. package/dist/__tests__/enhanced-cohesion.test.js +0 -119
  55. package/dist/__tests__/enhanced-cohesion.test.js.map +0 -1
  56. package/dist/__tests__/file-classification.test.d.ts +0 -2
  57. package/dist/__tests__/file-classification.test.d.ts.map +0 -1
  58. package/dist/__tests__/file-classification.test.js +0 -749
  59. package/dist/__tests__/file-classification.test.js.map +0 -1
  60. package/dist/__tests__/fragmentation-advanced.test.d.ts +0 -2
  61. package/dist/__tests__/fragmentation-advanced.test.d.ts.map +0 -1
  62. package/dist/__tests__/fragmentation-advanced.test.js +0 -44
  63. package/dist/__tests__/fragmentation-advanced.test.js.map +0 -1
  64. package/dist/__tests__/fragmentation-coupling.test.d.ts +0 -2
  65. package/dist/__tests__/fragmentation-coupling.test.d.ts.map +0 -1
  66. package/dist/__tests__/fragmentation-coupling.test.js +0 -52
  67. package/dist/__tests__/fragmentation-coupling.test.js.map +0 -1
  68. package/dist/__tests__/fragmentation-log.test.d.ts +0 -2
  69. package/dist/__tests__/fragmentation-log.test.d.ts.map +0 -1
  70. package/dist/__tests__/fragmentation-log.test.js +0 -29
  71. package/dist/__tests__/fragmentation-log.test.js.map +0 -1
  72. package/dist/__tests__/provider.test.d.ts +0 -2
  73. package/dist/__tests__/provider.test.d.ts.map +0 -1
  74. package/dist/__tests__/provider.test.js +0 -72
  75. package/dist/__tests__/provider.test.js.map +0 -1
  76. package/dist/__tests__/remediation.test.d.ts +0 -2
  77. package/dist/__tests__/remediation.test.d.ts.map +0 -1
  78. package/dist/__tests__/remediation.test.js +0 -61
  79. package/dist/__tests__/remediation.test.js.map +0 -1
  80. package/dist/__tests__/scoring.test.d.ts +0 -2
  81. package/dist/__tests__/scoring.test.d.ts.map +0 -1
  82. package/dist/__tests__/scoring.test.js +0 -298
  83. package/dist/__tests__/scoring.test.js.map +0 -1
  84. package/dist/__tests__/structural-cohesion.test.d.ts +0 -2
  85. package/dist/__tests__/structural-cohesion.test.d.ts.map +0 -1
  86. package/dist/__tests__/structural-cohesion.test.js +0 -35
  87. package/dist/__tests__/structural-cohesion.test.js.map +0 -1
  88. package/dist/analyzer.d.ts +0 -37
  89. package/dist/analyzer.d.ts.map +0 -1
  90. package/dist/analyzer.js +0 -283
  91. package/dist/analyzer.js.map +0 -1
  92. package/dist/analyzers/python-context.d.ts +0 -38
  93. package/dist/analyzers/python-context.d.ts.map +0 -1
  94. package/dist/analyzers/python-context.js +0 -234
  95. package/dist/analyzers/python-context.js.map +0 -1
  96. package/dist/ast-utils.d.ts +0 -16
  97. package/dist/ast-utils.d.ts.map +0 -1
  98. package/dist/ast-utils.js +0 -81
  99. package/dist/ast-utils.js.map +0 -1
  100. package/dist/chunk-22ZO4EKZ.mjs +0 -1297
  101. package/dist/chunk-2HE27YEV.mjs +0 -1739
  102. package/dist/chunk-45P4RDYP.mjs +0 -607
  103. package/dist/chunk-474DEGWW.mjs +0 -1792
  104. package/dist/chunk-4SYIJ7CU.mjs +0 -1538
  105. package/dist/chunk-4U4LDWGF.mjs +0 -360
  106. package/dist/chunk-4XQVYYPC.mjs +0 -1470
  107. package/dist/chunk-5CLU3HYU.mjs +0 -1475
  108. package/dist/chunk-5K73Q3OQ.mjs +0 -1520
  109. package/dist/chunk-5N5DCJOV.mjs +0 -583
  110. package/dist/chunk-6AVS4KTM.mjs +0 -1536
  111. package/dist/chunk-6FQYIG6I.mjs +0 -1298
  112. package/dist/chunk-6I4552YB.mjs +0 -1467
  113. package/dist/chunk-6LPITDKG.mjs +0 -1539
  114. package/dist/chunk-72QC5QUS.mjs +0 -549
  115. package/dist/chunk-736QSHJP.mjs +0 -1807
  116. package/dist/chunk-7LUSCLGR.mjs +0 -2058
  117. package/dist/chunk-7VK3XTSH.mjs +0 -1756
  118. package/dist/chunk-7ZEJGWLN.mjs +0 -1363
  119. package/dist/chunk-AECWO7NQ.mjs +0 -1539
  120. package/dist/chunk-AEK3MZC5.mjs +0 -709
  121. package/dist/chunk-AJC3FR6G.mjs +0 -1509
  122. package/dist/chunk-AMPK6SWS.mjs +0 -1754
  123. package/dist/chunk-BA7QGUHN.mjs +0 -1722
  124. package/dist/chunk-BCEZGRXI.mjs +0 -1297
  125. package/dist/chunk-BD4NWUVG.mjs +0 -1242
  126. package/dist/chunk-BEZPBI5C.mjs +0 -1829
  127. package/dist/chunk-BHCRDEE4.mjs +0 -1745
  128. package/dist/chunk-BW463GQB.mjs +0 -1767
  129. package/dist/chunk-CAX2MOUZ.mjs +0 -1801
  130. package/dist/chunk-CBWM3EK5.mjs +0 -1854
  131. package/dist/chunk-CCBNKQYB.mjs +0 -1812
  132. package/dist/chunk-CDIVYADN.mjs +0 -2110
  133. package/dist/chunk-CVGIDSMN.mjs +0 -1522
  134. package/dist/chunk-D25B5LZR.mjs +0 -1739
  135. package/dist/chunk-D3SIHB2V.mjs +0 -2118
  136. package/dist/chunk-DD7UVNE3.mjs +0 -678
  137. package/dist/chunk-DMRZMS2U.mjs +0 -964
  138. package/dist/chunk-DXG5NIYL.mjs +0 -1527
  139. package/dist/chunk-EBXG2Q5Y.mjs +0 -2059
  140. package/dist/chunk-EH3PMNZQ.mjs +0 -569
  141. package/dist/chunk-EMYD7NS6.mjs +0 -137
  142. package/dist/chunk-EVX2W2BK.mjs +0 -1896
  143. package/dist/chunk-EWFR366Y.mjs +0 -1740
  144. package/dist/chunk-EX7HCWAO.mjs +0 -625
  145. package/dist/chunk-FNPSK3CG.mjs +0 -1760
  146. package/dist/chunk-FO6YT6RG.mjs +0 -1751
  147. package/dist/chunk-FYI56A5M.mjs +0 -1892
  148. package/dist/chunk-G3CCJCBI.mjs +0 -1521
  149. package/dist/chunk-G7PO3DNK.mjs +0 -1072
  150. package/dist/chunk-GFADGYXZ.mjs +0 -1752
  151. package/dist/chunk-GTRIBVS6.mjs +0 -1467
  152. package/dist/chunk-GXTGOLZT.mjs +0 -92
  153. package/dist/chunk-H4HWBQU6.mjs +0 -1530
  154. package/dist/chunk-HDFXSEFW.mjs +0 -605
  155. package/dist/chunk-HOUDVRG2.mjs +0 -1422
  156. package/dist/chunk-HQNHM2X7.mjs +0 -997
  157. package/dist/chunk-I54HL4FZ.mjs +0 -781
  158. package/dist/chunk-I77HFFZU.mjs +0 -1876
  159. package/dist/chunk-IKRP7ECY.mjs +0 -1754
  160. package/dist/chunk-ILMLGJGI.mjs +0 -1295
  161. package/dist/chunk-IPIE5TXJ.mjs +0 -1741
  162. package/dist/chunk-IRWCPDWD.mjs +0 -779
  163. package/dist/chunk-J3MUOWHC.mjs +0 -1747
  164. package/dist/chunk-J5TA3AZU.mjs +0 -1795
  165. package/dist/chunk-JH535NPP.mjs +0 -1619
  166. package/dist/chunk-JUHHOSHG.mjs +0 -1808
  167. package/dist/chunk-JZ2SE4DB.mjs +0 -1116
  168. package/dist/chunk-K2WFOBAZ.mjs +0 -1821
  169. package/dist/chunk-K6U64EL3.mjs +0 -517
  170. package/dist/chunk-KDUUZQBK.mjs +0 -1692
  171. package/dist/chunk-KGFWKSGJ.mjs +0 -1442
  172. package/dist/chunk-KGVMS4R5.mjs +0 -1750
  173. package/dist/chunk-KWIS5FQP.mjs +0 -1739
  174. package/dist/chunk-KYSZF5N6.mjs +0 -1876
  175. package/dist/chunk-LERPI33Y.mjs +0 -2060
  176. package/dist/chunk-M64RHH4D.mjs +0 -1896
  177. package/dist/chunk-MBE4AQP5.mjs +0 -1362
  178. package/dist/chunk-MR7WXHIE.mjs +0 -1833
  179. package/dist/chunk-MZP3G7TF.mjs +0 -2118
  180. package/dist/chunk-N2GQWNFG.mjs +0 -1527
  181. package/dist/chunk-N6XBOOVA.mjs +0 -564
  182. package/dist/chunk-NJUW6VED.mjs +0 -610
  183. package/dist/chunk-NOHK5DLU.mjs +0 -2173
  184. package/dist/chunk-NQA3F2HJ.mjs +0 -1532
  185. package/dist/chunk-NXXQ2U73.mjs +0 -1467
  186. package/dist/chunk-OP4G6GLN.mjs +0 -1876
  187. package/dist/chunk-ORLC5Y4J.mjs +0 -1787
  188. package/dist/chunk-OTCQL7DY.mjs +0 -2045
  189. package/dist/chunk-OUYSZZ7X.mjs +0 -1846
  190. package/dist/chunk-OZE3FVZT.mjs +0 -1089
  191. package/dist/chunk-P3T3H27S.mjs +0 -1895
  192. package/dist/chunk-P5YV5WIX.mjs +0 -1803
  193. package/dist/chunk-P74BO725.mjs +0 -1296
  194. package/dist/chunk-PDN74MG3.mjs +0 -1834
  195. package/dist/chunk-PJD4VCIH.mjs +0 -1722
  196. package/dist/chunk-PVVCCE6W.mjs +0 -755
  197. package/dist/chunk-PVVMK56C.mjs +0 -1793
  198. package/dist/chunk-Q2GDZ2FZ.mjs +0 -1794
  199. package/dist/chunk-QDGPR3L6.mjs +0 -1518
  200. package/dist/chunk-RQCIJO5Z.mjs +0 -1116
  201. package/dist/chunk-RRB2C34Q.mjs +0 -1738
  202. package/dist/chunk-RYIB5CWD.mjs +0 -781
  203. package/dist/chunk-S6OPP4L5.mjs +0 -1791
  204. package/dist/chunk-SAVOSPM3.mjs +0 -1522
  205. package/dist/chunk-SFK6XTJE.mjs +0 -2110
  206. package/dist/chunk-SIX4KMF2.mjs +0 -1468
  207. package/dist/chunk-SPAM2YJE.mjs +0 -1537
  208. package/dist/chunk-T6ZCOPPI.mjs +0 -538
  209. package/dist/chunk-TPF75CNP.mjs +0 -581
  210. package/dist/chunk-TWWPY7FD.mjs +0 -1754
  211. package/dist/chunk-U5R2FTCR.mjs +0 -1803
  212. package/dist/chunk-UG7OPVHB.mjs +0 -1521
  213. package/dist/chunk-UMZTAWDA.mjs +0 -1812
  214. package/dist/chunk-UU4HZ7ZT.mjs +0 -1849
  215. package/dist/chunk-UXC6QUZ7.mjs +0 -1801
  216. package/dist/chunk-VBWXHKGD.mjs +0 -1895
  217. package/dist/chunk-VIJTZPBI.mjs +0 -1470
  218. package/dist/chunk-VLV6MXPL.mjs +0 -1750
  219. package/dist/chunk-VTALAPQZ.mjs +0 -1241
  220. package/dist/chunk-W2KNBN6W.mjs +0 -1849
  221. package/dist/chunk-W37E7MW5.mjs +0 -1403
  222. package/dist/chunk-W76FEISE.mjs +0 -1538
  223. package/dist/chunk-WCFQYXQA.mjs +0 -1532
  224. package/dist/chunk-WKOZOHOU.mjs +0 -2060
  225. package/dist/chunk-WTQJNY4U.mjs +0 -1785
  226. package/dist/chunk-XBFM2Z4O.mjs +0 -1792
  227. package/dist/chunk-XIXAWCMS.mjs +0 -1760
  228. package/dist/chunk-XTAXUNQN.mjs +0 -1742
  229. package/dist/chunk-XY77XABG.mjs +0 -1545
  230. package/dist/chunk-XZ645X5U.mjs +0 -1425
  231. package/dist/chunk-Y6FXYEAI.mjs +0 -10
  232. package/dist/chunk-YCGDIGOG.mjs +0 -1467
  233. package/dist/chunk-YYB6NZE3.mjs +0 -1869
  234. package/dist/chunk-Z5WY6A4P.mjs +0 -1754
  235. package/dist/chunk-ZAMFWKIB.mjs +0 -1842
  236. package/dist/classifier.d.ts +0 -114
  237. package/dist/classifier.d.ts.map +0 -1
  238. package/dist/classifier.js +0 -439
  239. package/dist/classifier.js.map +0 -1
  240. package/dist/cli-action-SA7SCYNV.mjs +0 -95
  241. package/dist/cli-action-VCXBZGZP.mjs +0 -95
  242. package/dist/cli-action-YAJOJCXJ.mjs +0 -95
  243. package/dist/cli.d.ts.map +0 -1
  244. package/dist/cli.js.map +0 -1
  245. package/dist/cluster-detector.d.ts +0 -8
  246. package/dist/cluster-detector.d.ts.map +0 -1
  247. package/dist/cluster-detector.js +0 -70
  248. package/dist/cluster-detector.js.map +0 -1
  249. package/dist/defaults.d.ts +0 -7
  250. package/dist/defaults.d.ts.map +0 -1
  251. package/dist/defaults.js +0 -54
  252. package/dist/defaults.js.map +0 -1
  253. package/dist/graph-builder.d.ts +0 -33
  254. package/dist/graph-builder.d.ts.map +0 -1
  255. package/dist/graph-builder.js +0 -225
  256. package/dist/graph-builder.js.map +0 -1
  257. package/dist/index.d.ts.map +0 -1
  258. package/dist/index.js.map +0 -1
  259. package/dist/metrics.d.ts +0 -34
  260. package/dist/metrics.d.ts.map +0 -1
  261. package/dist/metrics.js +0 -170
  262. package/dist/metrics.js.map +0 -1
  263. package/dist/orchestrator-3L3NAZYP.mjs +0 -10
  264. package/dist/orchestrator-5AL3XBPZ.mjs +0 -10
  265. package/dist/orchestrator-KMAKMHTD.mjs +0 -10
  266. package/dist/orchestrator-MONOZHVW.mjs +0 -10
  267. package/dist/orchestrator-R6MZT4Z2.mjs +0 -10
  268. package/dist/orchestrator-ZR7JSKWI.mjs +0 -10
  269. package/dist/provider.d.ts +0 -6
  270. package/dist/provider.d.ts.map +0 -1
  271. package/dist/provider.js +0 -48
  272. package/dist/provider.js.map +0 -1
  273. package/dist/python-context-3GZKN3LR.mjs +0 -162
  274. package/dist/python-context-GOH747QU.mjs +0 -202
  275. package/dist/python-context-O2EN3M6Z.mjs +0 -162
  276. package/dist/python-context-PAETRLDY.mjs +0 -185
  277. package/dist/python-context-TBI5FVFY.mjs +0 -203
  278. package/dist/python-context-UOPTQH44.mjs +0 -192
  279. package/dist/remediation.d.ts +0 -25
  280. package/dist/remediation.d.ts.map +0 -1
  281. package/dist/remediation.js +0 -98
  282. package/dist/remediation.js.map +0 -1
  283. package/dist/scoring.d.ts +0 -9
  284. package/dist/scoring.d.ts.map +0 -1
  285. package/dist/scoring.js +0 -142
  286. package/dist/scoring.js.map +0 -1
  287. package/dist/semantic-analysis.d.ts +0 -33
  288. package/dist/semantic-analysis.d.ts.map +0 -1
  289. package/dist/semantic-analysis.js +0 -303
  290. package/dist/semantic-analysis.js.map +0 -1
  291. package/dist/summary-7PZVW72O.mjs +0 -7
  292. package/dist/summary-LKUCJAIS.mjs +0 -7
  293. package/dist/summary.d.ts +0 -6
  294. package/dist/summary.d.ts.map +0 -1
  295. package/dist/summary.js +0 -92
  296. package/dist/summary.js.map +0 -1
  297. package/dist/types.d.ts +0 -124
  298. package/dist/types.d.ts.map +0 -1
  299. package/dist/types.js +0 -2
  300. package/dist/types.js.map +0 -1
  301. package/dist/utils/output-formatter.d.ts +0 -14
  302. package/dist/utils/output-formatter.d.ts.map +0 -1
  303. package/dist/utils/output-formatter.js +0 -338
  304. package/dist/utils/output-formatter.js.map +0 -1
@@ -1,78 +1,12 @@
1
- import { describe, it, expect, vi } from 'vitest';
2
- import { ContextAnalyzerProvider } from '../provider';
3
- import * as analyzer from '../index';
4
- import * as summary from '../summary';
5
-
6
- vi.mock('../orchestrator', async () => {
7
- const actual = await vi.importActual('../orchestrator');
8
- return {
9
- ...actual,
10
- analyzeContext: vi.fn(),
11
- };
12
- });
13
-
14
- vi.mock('../summary', async () => {
15
- const actual = await vi.importActual('../summary');
16
- return {
17
- ...actual,
18
- generateSummary: vi.fn(),
19
- };
20
- });
1
+ import { describe, it, expect } from 'vitest';
2
+ import { CONTEXT_ANALYZER_PROVIDER } from '../provider';
21
3
 
22
4
  describe('Context Analyzer Provider', () => {
23
- it('should analyze and return SpokeOutput', async () => {
24
- vi.mocked(analyzer.analyzeContext).mockResolvedValue([
25
- {
26
- file: 'file1.ts',
27
- issues: ['issue'],
28
- severity: 'major',
29
- recommendations: ['fix'],
30
- tokenCost: 100,
31
- importDepth: 2,
32
- contextBudget: 500,
33
- cohesionScore: 0.8,
34
- fragmentationScore: 0.1,
35
- dependencyCount: 5,
36
- dependencyList: [],
37
- circularDeps: [],
38
- domains: [],
39
- exportCount: 1,
40
- relatedFiles: [],
41
- fileClassification: 'unknown',
42
- potentialSavings: 0,
43
- linesOfCode: 50,
44
- } as any,
45
- ]);
46
- vi.mocked(summary.generateSummary).mockReturnValue({
47
- totalFiles: 1,
48
- } as any);
49
-
50
- const output = await ContextAnalyzerProvider.analyze({ rootDir: '.' });
51
-
52
- expect(output.summary.totalFiles).toBe(1);
53
- expect(output.results[0].fileName).toBe('file1.ts');
5
+ it('should have correct ID', () => {
6
+ expect(CONTEXT_ANALYZER_PROVIDER.id).toBe('context-analyzer');
54
7
  });
55
8
 
56
- it('should score an output', () => {
57
- const mockOutput = {
58
- summary: {
59
- score: 80,
60
- avgContextBudget: 1000,
61
- maxContextBudget: 5000,
62
- avgImportDepth: 3,
63
- maxImportDepth: 5,
64
- avgFragmentation: 0.2,
65
- criticalIssues: 0,
66
- majorIssues: 0,
67
- totalFiles: 10,
68
- } as any,
69
- results: [],
70
- };
71
-
72
- const scoring = ContextAnalyzerProvider.score(mockOutput as any, {
73
- rootDir: '.',
74
- });
75
- expect(scoring.score).toBeDefined();
76
- expect(scoring.toolName).toBe('context-analyzer');
9
+ it('should have alias', () => {
10
+ expect(CONTEXT_ANALYZER_PROVIDER.alias).toContain('context');
77
11
  });
78
12
  });
package/src/classifier.ts CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  /**
18
18
  * Constants for file classifications to avoid magic strings
19
19
  */
20
- export const Classification = {
20
+ export const CLASSIFICATION = {
21
21
  BARREL: 'barrel-export' as const,
22
22
  BOILERPLATE: 'boilerplate-barrel' as const,
23
23
  TYPE_DEFINITION: 'type-definition' as const,
@@ -48,81 +48,81 @@ export function classifyFile(
48
48
  ): FileClassification {
49
49
  // 1. Detect boilerplate barrels (pure indirection/architectural theater)
50
50
  if (isBoilerplateBarrel(node)) {
51
- return Classification.BOILERPLATE;
51
+ return CLASSIFICATION.BOILERPLATE;
52
52
  }
53
53
 
54
54
  // 2. Detect legitimate barrel exports (primarily re-exports that aggregate)
55
55
  if (isBarrelExport(node)) {
56
- return Classification.BARREL;
56
+ return CLASSIFICATION.BARREL;
57
57
  }
58
58
 
59
59
  // 2. Detect type definition files
60
60
  if (isTypeDefinition(node)) {
61
- return Classification.TYPE_DEFINITION;
61
+ return CLASSIFICATION.TYPE_DEFINITION;
62
62
  }
63
63
 
64
64
  // 3. Detect Next.js App Router pages
65
65
  if (isNextJsPage(node)) {
66
- return Classification.NEXTJS_PAGE;
66
+ return CLASSIFICATION.NEXTJS_PAGE;
67
67
  }
68
68
 
69
69
  // 4. Detect Lambda handlers
70
70
  if (isLambdaHandler(node)) {
71
- return Classification.LAMBDA_HANDLER;
71
+ return CLASSIFICATION.LAMBDA_HANDLER;
72
72
  }
73
73
 
74
74
  // 5. Detect Service files
75
75
  if (isServiceFile(node)) {
76
- return Classification.SERVICE;
76
+ return CLASSIFICATION.SERVICE;
77
77
  }
78
78
 
79
79
  // 6. Detect Email templates
80
80
  if (isEmailTemplate(node)) {
81
- return Classification.EMAIL_TEMPLATE;
81
+ return CLASSIFICATION.EMAIL_TEMPLATE;
82
82
  }
83
83
 
84
84
  // 7. Detect Parser/Transformer files
85
85
  if (isParserFile(node)) {
86
- return Classification.PARSER;
86
+ return CLASSIFICATION.PARSER;
87
87
  }
88
88
 
89
89
  // 8. Detect Session/State management files
90
90
  if (isSessionFile(node)) {
91
91
  // If it has high cohesion, it's a cohesive module
92
92
  if (cohesionScore >= 0.25 && domains.length <= 1)
93
- return Classification.COHESIVE_MODULE;
94
- return Classification.UTILITY_MODULE; // Group with utility for now
93
+ return CLASSIFICATION.COHESIVE_MODULE;
94
+ return CLASSIFICATION.UTILITY_MODULE; // Group with utility for now
95
95
  }
96
96
 
97
97
  // 9. Detect Utility modules (multi-domain but functional purpose)
98
98
  if (isUtilityModule(node)) {
99
- return Classification.UTILITY_MODULE;
99
+ return CLASSIFICATION.UTILITY_MODULE;
100
100
  }
101
101
 
102
102
  // 10. Detect Config/Schema files
103
103
  if (isConfigFile(node)) {
104
- return Classification.COHESIVE_MODULE;
104
+ return CLASSIFICATION.COHESIVE_MODULE;
105
105
  }
106
106
 
107
107
  // 11. Detect Spoke modules in monorepo
108
108
  if (isHubAndSpokeFile(node)) {
109
- return Classification.SPOKE_MODULE;
109
+ return CLASSIFICATION.SPOKE_MODULE;
110
110
  }
111
111
 
112
112
  // Cohesion and Domain heuristics
113
113
  if (domains.length <= 1 && domains[0] !== 'unknown') {
114
- return Classification.COHESIVE_MODULE;
114
+ return CLASSIFICATION.COHESIVE_MODULE;
115
115
  }
116
116
 
117
117
  if (domains.length > 1 && cohesionScore < 0.4) {
118
- return Classification.MIXED_CONCERNS;
118
+ return CLASSIFICATION.MIXED_CONCERNS;
119
119
  }
120
120
 
121
121
  if (cohesionScore >= 0.7) {
122
- return Classification.COHESIVE_MODULE;
122
+ return CLASSIFICATION.COHESIVE_MODULE;
123
123
  }
124
124
 
125
- return Classification.UNKNOWN;
125
+ return CLASSIFICATION.UNKNOWN;
126
126
  }
127
127
 
128
128
  // [Split Point] Logic below this point handled by heuristics.ts
@@ -141,15 +141,15 @@ export function adjustCohesionForClassification(
141
141
  node?: DependencyNode
142
142
  ): number {
143
143
  switch (classification) {
144
- case Classification.BOILERPLATE:
144
+ case CLASSIFICATION.BOILERPLATE:
145
145
  return 0.2; // Redundant indirection is low cohesion (architectural theater)
146
- case Classification.BARREL:
146
+ case CLASSIFICATION.BARREL:
147
147
  return 1;
148
- case Classification.TYPE_DEFINITION:
148
+ case CLASSIFICATION.TYPE_DEFINITION:
149
149
  return 1;
150
- case Classification.NEXTJS_PAGE:
150
+ case CLASSIFICATION.NEXTJS_PAGE:
151
151
  return 1;
152
- case Classification.UTILITY_MODULE: {
152
+ case CLASSIFICATION.UTILITY_MODULE: {
153
153
  if (
154
154
  node &&
155
155
  hasRelatedExportNames(
@@ -160,19 +160,19 @@ export function adjustCohesionForClassification(
160
160
  }
161
161
  return Math.max(0.75, Math.min(1, baseCohesion + 0.35));
162
162
  }
163
- case Classification.SERVICE:
163
+ case CLASSIFICATION.SERVICE:
164
164
  return Math.max(0.72, Math.min(1, baseCohesion + 0.3));
165
- case Classification.LAMBDA_HANDLER:
165
+ case CLASSIFICATION.LAMBDA_HANDLER:
166
166
  return Math.max(0.75, Math.min(1, baseCohesion + 0.35));
167
- case Classification.EMAIL_TEMPLATE:
167
+ case CLASSIFICATION.EMAIL_TEMPLATE:
168
168
  return Math.max(0.72, Math.min(1, baseCohesion + 0.3));
169
- case Classification.PARSER:
169
+ case CLASSIFICATION.PARSER:
170
170
  return Math.max(0.7, Math.min(1, baseCohesion + 0.3));
171
- case Classification.SPOKE_MODULE:
171
+ case CLASSIFICATION.SPOKE_MODULE:
172
172
  return Math.max(baseCohesion, 0.6);
173
- case Classification.COHESIVE_MODULE:
173
+ case CLASSIFICATION.COHESIVE_MODULE:
174
174
  return Math.max(baseCohesion, 0.7);
175
- case Classification.MIXED_CONCERNS:
175
+ case CLASSIFICATION.MIXED_CONCERNS:
176
176
  return baseCohesion;
177
177
  default:
178
178
  return Math.min(1, baseCohesion + 0.1);
@@ -244,24 +244,24 @@ export function adjustFragmentationForClassification(
244
244
  classification: FileClassification
245
245
  ): number {
246
246
  switch (classification) {
247
- case Classification.BOILERPLATE:
247
+ case CLASSIFICATION.BOILERPLATE:
248
248
  return baseFragmentation * 1.5; // Redundant barrels increase fragmentation
249
- case Classification.BARREL:
249
+ case CLASSIFICATION.BARREL:
250
250
  return 0;
251
- case Classification.TYPE_DEFINITION:
251
+ case CLASSIFICATION.TYPE_DEFINITION:
252
252
  return 0;
253
- case Classification.UTILITY_MODULE:
254
- case Classification.SERVICE:
255
- case Classification.LAMBDA_HANDLER:
256
- case Classification.EMAIL_TEMPLATE:
257
- case Classification.PARSER:
258
- case Classification.NEXTJS_PAGE:
253
+ case CLASSIFICATION.UTILITY_MODULE:
254
+ case CLASSIFICATION.SERVICE:
255
+ case CLASSIFICATION.LAMBDA_HANDLER:
256
+ case CLASSIFICATION.EMAIL_TEMPLATE:
257
+ case CLASSIFICATION.PARSER:
258
+ case CLASSIFICATION.NEXTJS_PAGE:
259
259
  return baseFragmentation * 0.2;
260
- case Classification.SPOKE_MODULE:
260
+ case CLASSIFICATION.SPOKE_MODULE:
261
261
  return baseFragmentation * 0.15; // Heavily discount intentional monorepo separation
262
- case Classification.COHESIVE_MODULE:
262
+ case CLASSIFICATION.COHESIVE_MODULE:
263
263
  return baseFragmentation * 0.3;
264
- case Classification.MIXED_CONCERNS:
264
+ case CLASSIFICATION.MIXED_CONCERNS:
265
265
  return baseFragmentation;
266
266
  default:
267
267
  return baseFragmentation * 0.7;
package/src/cli-action.ts CHANGED
@@ -7,9 +7,6 @@ import {
7
7
  } from '@aiready/core';
8
8
  import { analyzeContext } from './orchestrator';
9
9
  import { generateSummary } from './summary';
10
- import { displayConsoleReport } from './report/console-report';
11
- import { generateHTMLReport } from './report/html-report';
12
- import { runInteractiveSetup } from './report/interactive-setup';
13
10
  import chalk from 'chalk';
14
11
  import { writeFileSync } from 'fs';
15
12
 
@@ -17,6 +14,9 @@ import { writeFileSync } from 'fs';
17
14
  * Orchestrates the context analysis CLI command.
18
15
  * Merges configuration, invokes the analyzer, and formats the output (Console/JSON/HTML).
19
16
  *
17
+ * Uses dynamic imports for heavy report generators to prune the static dependency tree
18
+ * and improve AI-readiness context budget metrics.
19
+ *
20
20
  * @param directory - Root directory to analyze
21
21
  * @param options - CLI options including focus area, max depth, and output format
22
22
  */
@@ -60,8 +60,10 @@ export async function contextActionHandler(directory: string, options: any) {
60
60
  maxResults: options.maxResults ? parseInt(options.maxResults) : undefined,
61
61
  });
62
62
 
63
- // Interactive setup if requested
63
+ // Interactive setup if requested (Dynamic Import)
64
64
  if (options.interactive) {
65
+ const { runInteractiveSetup } =
66
+ await import('./report/interactive-setup');
65
67
  finalOptions = await runInteractiveSetup(directory, finalOptions);
66
68
  }
67
69
 
@@ -89,6 +91,8 @@ export async function contextActionHandler(directory: string, options: any) {
89
91
  options.outputFile
90
92
  );
91
93
  } else if (options.output === 'html') {
94
+ // Dynamic Import for HTML Generator
95
+ const { generateHTMLReport } = await import('./report/html-report');
92
96
  const html = generateHTMLReport(summary, results);
93
97
  const outputPath = resolveOutputPath(
94
98
  directory,
@@ -98,8 +102,9 @@ export async function contextActionHandler(directory: string, options: any) {
98
102
  writeFileSync(outputPath, html, 'utf-8');
99
103
  console.log(chalk.green(`\n✅ HTML report saved to: ${outputPath}`));
100
104
  } else {
101
- // Default: Console
102
- displayConsoleReport(summary, results, finalOptions.maxResults);
105
+ // Default: Console (Dynamic Import)
106
+ const { displayConsoleReport } = await import('./report/console-report');
107
+ displayConsoleReport(summary, results, (finalOptions as any).maxResults);
103
108
  console.log(chalk.dim(`\n✨ Analysis completed in ${duration}ms\n`));
104
109
  }
105
110
  } catch (error) {
package/src/index.ts CHANGED
@@ -1,32 +1,35 @@
1
1
  import { ToolRegistry } from '@aiready/core';
2
- import { ContextAnalyzerProvider } from './provider';
2
+ import { CONTEXT_ANALYZER_PROVIDER } from './provider';
3
3
 
4
4
  // Register with global registry
5
- ToolRegistry.register(ContextAnalyzerProvider);
5
+ ToolRegistry.register(CONTEXT_ANALYZER_PROVIDER);
6
6
 
7
- export * from './orchestrator';
8
- export * from './graph-builder';
9
- export * from './metrics';
10
- export * from './classifier';
11
- export * from './cluster-detector';
12
- export * from './remediation';
13
- export * from './scoring';
14
- export * from './defaults';
15
- export * from './summary';
16
7
  export * from './types';
17
- // Semantic analysis modules - direct exports
18
- export * from './semantic/co-usage';
19
- export * from './semantic/type-graph';
20
- export * from './semantic/domain-inference';
21
- export * from './semantic/consolidation';
22
-
23
- // Classification modules
24
- export * from './classify/classification-patterns';
25
- export * from './classify/file-classifiers';
26
-
27
- // Report modules
28
- export * from './report/console-report';
29
- export * from './report/html-report';
30
- export * from './report/interactive-setup';
31
-
32
- export { ContextAnalyzerProvider };
8
+ export { analyzeContext, calculateCohesion } from './orchestrator';
9
+ export { calculateContextScore, mapScoreToRating } from './scoring';
10
+ export {
11
+ calculateEnhancedCohesion,
12
+ calculatePathEntropy,
13
+ calculateStructuralCohesionFromCoUsage,
14
+ calculateFragmentation,
15
+ calculateDirectoryDistance,
16
+ } from './metrics';
17
+ export { detectModuleClusters } from './cluster-detector';
18
+ export {
19
+ buildDependencyGraph,
20
+ detectCircularDependencies,
21
+ calculateContextBudget,
22
+ calculateImportDepth,
23
+ getTransitiveDependencies,
24
+ } from './graph-builder';
25
+ export {
26
+ classifyFile,
27
+ adjustCohesionForClassification,
28
+ adjustFragmentationForClassification,
29
+ } from './classifier';
30
+ export {
31
+ getClassificationRecommendations,
32
+ getGeneralRecommendations,
33
+ } from './remediation';
34
+ export { generateSummary } from './summary';
35
+ export { CONTEXT_ANALYZER_PROVIDER };
package/src/provider.ts CHANGED
@@ -19,7 +19,7 @@ import type {
19
19
  /**
20
20
  * Context Analyzer Tool Provider
21
21
  */
22
- export const ContextAnalyzerProvider: ToolProvider = {
22
+ export const CONTEXT_ANALYZER_PROVIDER: ToolProvider = {
23
23
  id: ToolName.ContextAnalyzer,
24
24
  alias: ['context', 'fragmentation', 'budget'],
25
25
 
package/src/summary.ts CHANGED
@@ -17,7 +17,7 @@ export function generateSummary(
17
17
  results: ContextAnalysisResult[],
18
18
  options: any = {}
19
19
  ): ContextSummary {
20
- const config = options
20
+ const config: Record<string, any> = options
21
21
  ? Object.fromEntries(
22
22
  Object.entries(options).filter(
23
23
  ([key]) => !GLOBAL_SCAN_OPTIONS.includes(key) || key === 'rootDir'
@@ -41,13 +41,50 @@ export function generateSummary(
41
41
 
42
42
  // Find fragmented modules (clusters)
43
43
  const moduleMap = new Map<string, ContextAnalysisResult[]>();
44
+ const rootDir = config.rootDir || '';
45
+
44
46
  results.forEach((r) => {
45
- const parts = r.file.split('/');
47
+ // Calculate relative path from root directory
48
+ let relativePath = r.file;
49
+ if (rootDir && r.file.startsWith(rootDir)) {
50
+ relativePath = r.file.slice(rootDir.length);
51
+ if (relativePath.startsWith('/')) relativePath = relativePath.slice(1);
52
+ }
53
+
54
+ const parts = relativePath.split('/');
55
+
46
56
  // Try to identify domain/module (e.g., packages/core, src/utils)
57
+ // For monorepos, look for 'packages/<name>' or 'apps/<name>' patterns
47
58
  let domain = 'root';
48
- if (parts.length > 2) {
49
- domain = parts.slice(0, 2).join('/');
59
+
60
+ // Find meaningful domain directory
61
+ const domainIndicators = ['packages', 'apps', 'src', 'lib', 'modules'];
62
+ for (let i = 0; i < parts.length - 1; i++) {
63
+ if (domainIndicators.includes(parts[i]) && parts[i + 1]) {
64
+ domain = `${parts[i]}/${parts[i + 1]}`;
65
+ break;
66
+ }
50
67
  }
68
+
69
+ // Fallback: use first meaningful directory
70
+ if (domain === 'root' && parts.length > 1) {
71
+ // Skip common non-domain prefixes
72
+ const skipPrefixes = [
73
+ 'src',
74
+ 'lib',
75
+ 'dist',
76
+ 'build',
77
+ 'out',
78
+ 'node_modules',
79
+ ];
80
+ for (let i = 0; i < parts.length - 1; i++) {
81
+ if (!skipPrefixes.includes(parts[i]) && parts[i] !== '') {
82
+ domain = parts[i];
83
+ break;
84
+ }
85
+ }
86
+ }
87
+
51
88
  if (!moduleMap.has(domain)) moduleMap.set(domain, []);
52
89
  moduleMap.get(domain)!.push(r);
53
90
  });
@@ -57,10 +94,29 @@ export function generateSummary(
57
94
  const clusterTokens = files.reduce((sum, f) => sum + f.tokenCost, 0);
58
95
  const filePaths = files.map((f) => f.file);
59
96
  const avgEntropy = calculatePathEntropy(filePaths);
60
-
61
- // A module is fragmented if it has many files with high directory distance
62
- // and relatively low cohesion
63
- const fragmentationScore = Math.min(1, avgEntropy * (files.length / 10));
97
+ const avgCohesion =
98
+ files.reduce((sum, f) => sum + f.cohesionScore, 0) / files.length;
99
+
100
+ // For monorepos, files within a domain are naturally organized into subdirectories.
101
+ // Fragmentation should only be high if:
102
+ // 1. Files are spread across many unrelated directories (high entropy)
103
+ // 2. AND the cohesion is low (files don't share types/imports)
104
+ // 3. AND there are many files (small domains are less concerning)
105
+ //
106
+ // Use a more lenient calculation that accounts for monorepo structure:
107
+ // - Low cohesion (< 0.5) contributes to fragmentation
108
+ // - High entropy contributes to fragmentation
109
+ // - But allow for subdirectory organization within a domain
110
+ const cohesionFactor = avgCohesion < 0.5 ? (0.5 - avgCohesion) * 2 : 0;
111
+ const entropyFactor = avgEntropy > 0.7 ? (avgEntropy - 0.7) * 3.33 : 0;
112
+ const sizeFactor =
113
+ files.length > 20 ? Math.min(1, (files.length - 20) / 80) : 0;
114
+
115
+ // Combined fragmentation score with lower weight for entropy in monorepos
116
+ const fragmentationScore = Math.min(
117
+ 1,
118
+ cohesionFactor * 0.5 + entropyFactor * 0.3 + sizeFactor * 0.2
119
+ );
64
120
 
65
121
  if (fragmentationScore > 0.4) {
66
122
  fragmentedModules.push({
@@ -68,8 +124,7 @@ export function generateSummary(
68
124
  files: filePaths,
69
125
  fragmentationScore,
70
126
  totalTokens: clusterTokens,
71
- avgCohesion:
72
- files.reduce((sum, f) => sum + f.cohesionScore, 0) / files.length,
127
+ avgCohesion,
73
128
  suggestedStructure: {
74
129
  targetFiles: Math.ceil(files.length / 2),
75
130
  consolidationPlan: [
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=analyzer.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"analyzer.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/analyzer.test.ts"],"names":[],"mappings":""}