@aiready/context-analyzer 0.22.9 → 0.22.12
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.
- package/.turbo/turbo-build.log +33 -32
- package/.turbo/turbo-format-check.log +1 -1
- package/.turbo/turbo-lint.log +8 -0
- package/dist/chunk-HD4Y3GYL.mjs +124 -0
- package/dist/{chunk-M2EGQ36M.mjs → chunk-ISWPFG2C.mjs} +43 -98
- package/dist/{chunk-BQCISA2F.mjs → chunk-QW6ULRML.mjs} +32 -6
- package/dist/{chunk-WHB7QI7N.mjs → chunk-T733LS62.mjs} +23 -4
- package/dist/{cli-action-CXIHOVAC.mjs → cli-action-FV4G4OB6.mjs} +3 -3
- package/dist/{cli-action-3CWN7PBE.mjs → cli-action-HYSWE7F4.mjs} +3 -3
- package/dist/{cli-action-MLFCIW2O.mjs → cli-action-VIQZSWSP.mjs} +3 -3
- package/dist/{cli-action-E7UGP4KE.mjs → cli-action-W7TESWAV.mjs} +6 -8
- package/dist/cli.js +236 -191
- package/dist/cli.mjs +1 -1
- package/dist/console-report-AP4JYNQY.mjs +74 -0
- package/dist/html-report-ULELSIYG.mjs +73 -0
- package/dist/index.d.mts +69 -337
- package/dist/index.d.ts +69 -337
- package/dist/index.js +90 -452
- package/dist/index.mjs +9 -157
- package/dist/interactive-setup-JGFBFI3M.mjs +75 -0
- package/dist/{orchestrator-3ERQS3NW.mjs → orchestrator-QNE2E4TE.mjs} +2 -2
- package/dist/summary-GQRWW3A2.mjs +7 -0
- package/dist/summary-JTBS7CPM.mjs +7 -0
- package/dist/summary-TZFB6ZFM.mjs +7 -0
- package/package.json +2 -2
- package/src/__tests__/file-classification.fixtures.ts +57 -0
- package/src/__tests__/file-classification.test.ts +24 -929
- package/src/__tests__/provider.test.ts +6 -72
- package/src/classifier.ts +42 -42
- package/src/cli-action.ts +11 -6
- package/src/index.ts +30 -27
- package/src/provider.ts +1 -1
- package/src/summary.ts +65 -10
- package/dist/__tests__/analyzer.test.d.ts +0 -2
- package/dist/__tests__/analyzer.test.d.ts.map +0 -1
- package/dist/__tests__/analyzer.test.js +0 -198
- package/dist/__tests__/analyzer.test.js.map +0 -1
- package/dist/__tests__/auto-detection.test.d.ts +0 -2
- package/dist/__tests__/auto-detection.test.d.ts.map +0 -1
- package/dist/__tests__/auto-detection.test.js +0 -132
- package/dist/__tests__/auto-detection.test.js.map +0 -1
- package/dist/__tests__/cluster-detector.test.d.ts +0 -2
- package/dist/__tests__/cluster-detector.test.d.ts.map +0 -1
- package/dist/__tests__/cluster-detector.test.js +0 -121
- package/dist/__tests__/cluster-detector.test.js.map +0 -1
- package/dist/__tests__/contract.test.d.ts +0 -2
- package/dist/__tests__/contract.test.d.ts.map +0 -1
- package/dist/__tests__/contract.test.js +0 -59
- package/dist/__tests__/contract.test.js.map +0 -1
- package/dist/__tests__/enhanced-cohesion.test.d.ts +0 -2
- package/dist/__tests__/enhanced-cohesion.test.d.ts.map +0 -1
- package/dist/__tests__/enhanced-cohesion.test.js +0 -119
- package/dist/__tests__/enhanced-cohesion.test.js.map +0 -1
- package/dist/__tests__/file-classification.test.d.ts +0 -2
- package/dist/__tests__/file-classification.test.d.ts.map +0 -1
- package/dist/__tests__/file-classification.test.js +0 -749
- package/dist/__tests__/file-classification.test.js.map +0 -1
- package/dist/__tests__/fragmentation-advanced.test.d.ts +0 -2
- package/dist/__tests__/fragmentation-advanced.test.d.ts.map +0 -1
- package/dist/__tests__/fragmentation-advanced.test.js +0 -44
- package/dist/__tests__/fragmentation-advanced.test.js.map +0 -1
- package/dist/__tests__/fragmentation-coupling.test.d.ts +0 -2
- package/dist/__tests__/fragmentation-coupling.test.d.ts.map +0 -1
- package/dist/__tests__/fragmentation-coupling.test.js +0 -52
- package/dist/__tests__/fragmentation-coupling.test.js.map +0 -1
- package/dist/__tests__/fragmentation-log.test.d.ts +0 -2
- package/dist/__tests__/fragmentation-log.test.d.ts.map +0 -1
- package/dist/__tests__/fragmentation-log.test.js +0 -29
- package/dist/__tests__/fragmentation-log.test.js.map +0 -1
- package/dist/__tests__/provider.test.d.ts +0 -2
- package/dist/__tests__/provider.test.d.ts.map +0 -1
- package/dist/__tests__/provider.test.js +0 -72
- package/dist/__tests__/provider.test.js.map +0 -1
- package/dist/__tests__/remediation.test.d.ts +0 -2
- package/dist/__tests__/remediation.test.d.ts.map +0 -1
- package/dist/__tests__/remediation.test.js +0 -61
- package/dist/__tests__/remediation.test.js.map +0 -1
- package/dist/__tests__/scoring.test.d.ts +0 -2
- package/dist/__tests__/scoring.test.d.ts.map +0 -1
- package/dist/__tests__/scoring.test.js +0 -298
- package/dist/__tests__/scoring.test.js.map +0 -1
- package/dist/__tests__/structural-cohesion.test.d.ts +0 -2
- package/dist/__tests__/structural-cohesion.test.d.ts.map +0 -1
- package/dist/__tests__/structural-cohesion.test.js +0 -35
- package/dist/__tests__/structural-cohesion.test.js.map +0 -1
- package/dist/analyzer.d.ts +0 -37
- package/dist/analyzer.d.ts.map +0 -1
- package/dist/analyzer.js +0 -283
- package/dist/analyzer.js.map +0 -1
- package/dist/analyzers/python-context.d.ts +0 -38
- package/dist/analyzers/python-context.d.ts.map +0 -1
- package/dist/analyzers/python-context.js +0 -234
- package/dist/analyzers/python-context.js.map +0 -1
- package/dist/ast-utils.d.ts +0 -16
- package/dist/ast-utils.d.ts.map +0 -1
- package/dist/ast-utils.js +0 -81
- package/dist/ast-utils.js.map +0 -1
- package/dist/chunk-22ZO4EKZ.mjs +0 -1297
- package/dist/chunk-2HE27YEV.mjs +0 -1739
- package/dist/chunk-45P4RDYP.mjs +0 -607
- package/dist/chunk-474DEGWW.mjs +0 -1792
- package/dist/chunk-4SYIJ7CU.mjs +0 -1538
- package/dist/chunk-4U4LDWGF.mjs +0 -360
- package/dist/chunk-4XQVYYPC.mjs +0 -1470
- package/dist/chunk-5CLU3HYU.mjs +0 -1475
- package/dist/chunk-5K73Q3OQ.mjs +0 -1520
- package/dist/chunk-5N5DCJOV.mjs +0 -583
- package/dist/chunk-6AVS4KTM.mjs +0 -1536
- package/dist/chunk-6FQYIG6I.mjs +0 -1298
- package/dist/chunk-6I4552YB.mjs +0 -1467
- package/dist/chunk-6LPITDKG.mjs +0 -1539
- package/dist/chunk-72QC5QUS.mjs +0 -549
- package/dist/chunk-736QSHJP.mjs +0 -1807
- package/dist/chunk-7LUSCLGR.mjs +0 -2058
- package/dist/chunk-7VK3XTSH.mjs +0 -1756
- package/dist/chunk-7ZEJGWLN.mjs +0 -1363
- package/dist/chunk-AECWO7NQ.mjs +0 -1539
- package/dist/chunk-AEK3MZC5.mjs +0 -709
- package/dist/chunk-AJC3FR6G.mjs +0 -1509
- package/dist/chunk-AMPK6SWS.mjs +0 -1754
- package/dist/chunk-BA7QGUHN.mjs +0 -1722
- package/dist/chunk-BCEZGRXI.mjs +0 -1297
- package/dist/chunk-BD4NWUVG.mjs +0 -1242
- package/dist/chunk-BEZPBI5C.mjs +0 -1829
- package/dist/chunk-BHCRDEE4.mjs +0 -1745
- package/dist/chunk-BW463GQB.mjs +0 -1767
- package/dist/chunk-CAX2MOUZ.mjs +0 -1801
- package/dist/chunk-CBWM3EK5.mjs +0 -1854
- package/dist/chunk-CCBNKQYB.mjs +0 -1812
- package/dist/chunk-CDIVYADN.mjs +0 -2110
- package/dist/chunk-CVGIDSMN.mjs +0 -1522
- package/dist/chunk-D25B5LZR.mjs +0 -1739
- package/dist/chunk-D3SIHB2V.mjs +0 -2118
- package/dist/chunk-DD7UVNE3.mjs +0 -678
- package/dist/chunk-DMRZMS2U.mjs +0 -964
- package/dist/chunk-DXG5NIYL.mjs +0 -1527
- package/dist/chunk-EBXG2Q5Y.mjs +0 -2059
- package/dist/chunk-EH3PMNZQ.mjs +0 -569
- package/dist/chunk-EMYD7NS6.mjs +0 -137
- package/dist/chunk-EVX2W2BK.mjs +0 -1896
- package/dist/chunk-EWFR366Y.mjs +0 -1740
- package/dist/chunk-EX7HCWAO.mjs +0 -625
- package/dist/chunk-FNPSK3CG.mjs +0 -1760
- package/dist/chunk-FO6YT6RG.mjs +0 -1751
- package/dist/chunk-FYI56A5M.mjs +0 -1892
- package/dist/chunk-G3CCJCBI.mjs +0 -1521
- package/dist/chunk-G7PO3DNK.mjs +0 -1072
- package/dist/chunk-GFADGYXZ.mjs +0 -1752
- package/dist/chunk-GTRIBVS6.mjs +0 -1467
- package/dist/chunk-GXTGOLZT.mjs +0 -92
- package/dist/chunk-H4HWBQU6.mjs +0 -1530
- package/dist/chunk-HDFXSEFW.mjs +0 -605
- package/dist/chunk-HOUDVRG2.mjs +0 -1422
- package/dist/chunk-HQNHM2X7.mjs +0 -997
- package/dist/chunk-I54HL4FZ.mjs +0 -781
- package/dist/chunk-I77HFFZU.mjs +0 -1876
- package/dist/chunk-IKRP7ECY.mjs +0 -1754
- package/dist/chunk-ILMLGJGI.mjs +0 -1295
- package/dist/chunk-IPIE5TXJ.mjs +0 -1741
- package/dist/chunk-IRWCPDWD.mjs +0 -779
- package/dist/chunk-J3MUOWHC.mjs +0 -1747
- package/dist/chunk-J5TA3AZU.mjs +0 -1795
- package/dist/chunk-JH535NPP.mjs +0 -1619
- package/dist/chunk-JUHHOSHG.mjs +0 -1808
- package/dist/chunk-JZ2SE4DB.mjs +0 -1116
- package/dist/chunk-K2WFOBAZ.mjs +0 -1821
- package/dist/chunk-K6U64EL3.mjs +0 -517
- package/dist/chunk-KDUUZQBK.mjs +0 -1692
- package/dist/chunk-KGFWKSGJ.mjs +0 -1442
- package/dist/chunk-KGVMS4R5.mjs +0 -1750
- package/dist/chunk-KWIS5FQP.mjs +0 -1739
- package/dist/chunk-KYSZF5N6.mjs +0 -1876
- package/dist/chunk-LERPI33Y.mjs +0 -2060
- package/dist/chunk-M64RHH4D.mjs +0 -1896
- package/dist/chunk-MBE4AQP5.mjs +0 -1362
- package/dist/chunk-MR7WXHIE.mjs +0 -1833
- package/dist/chunk-MZP3G7TF.mjs +0 -2118
- package/dist/chunk-N2GQWNFG.mjs +0 -1527
- package/dist/chunk-N6XBOOVA.mjs +0 -564
- package/dist/chunk-NJUW6VED.mjs +0 -610
- package/dist/chunk-NOHK5DLU.mjs +0 -2173
- package/dist/chunk-NQA3F2HJ.mjs +0 -1532
- package/dist/chunk-NXXQ2U73.mjs +0 -1467
- package/dist/chunk-OP4G6GLN.mjs +0 -1876
- package/dist/chunk-ORLC5Y4J.mjs +0 -1787
- package/dist/chunk-OTCQL7DY.mjs +0 -2045
- package/dist/chunk-OUYSZZ7X.mjs +0 -1846
- package/dist/chunk-OZE3FVZT.mjs +0 -1089
- package/dist/chunk-P3T3H27S.mjs +0 -1895
- package/dist/chunk-P5YV5WIX.mjs +0 -1803
- package/dist/chunk-P74BO725.mjs +0 -1296
- package/dist/chunk-PDN74MG3.mjs +0 -1834
- package/dist/chunk-PJD4VCIH.mjs +0 -1722
- package/dist/chunk-PVVCCE6W.mjs +0 -755
- package/dist/chunk-PVVMK56C.mjs +0 -1793
- package/dist/chunk-Q2GDZ2FZ.mjs +0 -1794
- package/dist/chunk-QDGPR3L6.mjs +0 -1518
- package/dist/chunk-RQCIJO5Z.mjs +0 -1116
- package/dist/chunk-RRB2C34Q.mjs +0 -1738
- package/dist/chunk-RYIB5CWD.mjs +0 -781
- package/dist/chunk-S6OPP4L5.mjs +0 -1791
- package/dist/chunk-SAVOSPM3.mjs +0 -1522
- package/dist/chunk-SFK6XTJE.mjs +0 -2110
- package/dist/chunk-SIX4KMF2.mjs +0 -1468
- package/dist/chunk-SPAM2YJE.mjs +0 -1537
- package/dist/chunk-T6ZCOPPI.mjs +0 -538
- package/dist/chunk-TPF75CNP.mjs +0 -581
- package/dist/chunk-TWWPY7FD.mjs +0 -1754
- package/dist/chunk-U5R2FTCR.mjs +0 -1803
- package/dist/chunk-UG7OPVHB.mjs +0 -1521
- package/dist/chunk-UMZTAWDA.mjs +0 -1812
- package/dist/chunk-UU4HZ7ZT.mjs +0 -1849
- package/dist/chunk-UXC6QUZ7.mjs +0 -1801
- package/dist/chunk-VBWXHKGD.mjs +0 -1895
- package/dist/chunk-VIJTZPBI.mjs +0 -1470
- package/dist/chunk-VLV6MXPL.mjs +0 -1750
- package/dist/chunk-VTALAPQZ.mjs +0 -1241
- package/dist/chunk-W2KNBN6W.mjs +0 -1849
- package/dist/chunk-W37E7MW5.mjs +0 -1403
- package/dist/chunk-W76FEISE.mjs +0 -1538
- package/dist/chunk-WCFQYXQA.mjs +0 -1532
- package/dist/chunk-WKOZOHOU.mjs +0 -2060
- package/dist/chunk-WTQJNY4U.mjs +0 -1785
- package/dist/chunk-XBFM2Z4O.mjs +0 -1792
- package/dist/chunk-XIXAWCMS.mjs +0 -1760
- package/dist/chunk-XTAXUNQN.mjs +0 -1742
- package/dist/chunk-XY77XABG.mjs +0 -1545
- package/dist/chunk-XZ645X5U.mjs +0 -1425
- package/dist/chunk-Y6FXYEAI.mjs +0 -10
- package/dist/chunk-YCGDIGOG.mjs +0 -1467
- package/dist/chunk-YYB6NZE3.mjs +0 -1869
- package/dist/chunk-Z5WY6A4P.mjs +0 -1754
- package/dist/chunk-ZAMFWKIB.mjs +0 -1842
- package/dist/classifier.d.ts +0 -114
- package/dist/classifier.d.ts.map +0 -1
- package/dist/classifier.js +0 -439
- package/dist/classifier.js.map +0 -1
- package/dist/cli-action-SA7SCYNV.mjs +0 -95
- package/dist/cli-action-VCXBZGZP.mjs +0 -95
- package/dist/cli-action-YAJOJCXJ.mjs +0 -95
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/cluster-detector.d.ts +0 -8
- package/dist/cluster-detector.d.ts.map +0 -1
- package/dist/cluster-detector.js +0 -70
- package/dist/cluster-detector.js.map +0 -1
- package/dist/defaults.d.ts +0 -7
- package/dist/defaults.d.ts.map +0 -1
- package/dist/defaults.js +0 -54
- package/dist/defaults.js.map +0 -1
- package/dist/graph-builder.d.ts +0 -33
- package/dist/graph-builder.d.ts.map +0 -1
- package/dist/graph-builder.js +0 -225
- package/dist/graph-builder.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/metrics.d.ts +0 -34
- package/dist/metrics.d.ts.map +0 -1
- package/dist/metrics.js +0 -170
- package/dist/metrics.js.map +0 -1
- package/dist/orchestrator-3L3NAZYP.mjs +0 -10
- package/dist/orchestrator-5AL3XBPZ.mjs +0 -10
- package/dist/orchestrator-KMAKMHTD.mjs +0 -10
- package/dist/orchestrator-MONOZHVW.mjs +0 -10
- package/dist/orchestrator-R6MZT4Z2.mjs +0 -10
- package/dist/orchestrator-ZR7JSKWI.mjs +0 -10
- package/dist/provider.d.ts +0 -6
- package/dist/provider.d.ts.map +0 -1
- package/dist/provider.js +0 -48
- package/dist/provider.js.map +0 -1
- package/dist/python-context-3GZKN3LR.mjs +0 -162
- package/dist/python-context-GOH747QU.mjs +0 -202
- package/dist/python-context-O2EN3M6Z.mjs +0 -162
- package/dist/python-context-PAETRLDY.mjs +0 -185
- package/dist/python-context-TBI5FVFY.mjs +0 -203
- package/dist/python-context-UOPTQH44.mjs +0 -192
- package/dist/remediation.d.ts +0 -25
- package/dist/remediation.d.ts.map +0 -1
- package/dist/remediation.js +0 -98
- package/dist/remediation.js.map +0 -1
- package/dist/scoring.d.ts +0 -9
- package/dist/scoring.d.ts.map +0 -1
- package/dist/scoring.js +0 -142
- package/dist/scoring.js.map +0 -1
- package/dist/semantic-analysis.d.ts +0 -33
- package/dist/semantic-analysis.d.ts.map +0 -1
- package/dist/semantic-analysis.js +0 -303
- package/dist/semantic-analysis.js.map +0 -1
- package/dist/summary-7PZVW72O.mjs +0 -7
- package/dist/summary-LKUCJAIS.mjs +0 -7
- package/dist/summary.d.ts +0 -6
- package/dist/summary.d.ts.map +0 -1
- package/dist/summary.js +0 -92
- package/dist/summary.js.map +0 -1
- package/dist/types.d.ts +0 -124
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/utils/output-formatter.d.ts +0 -14
- package/dist/utils/output-formatter.d.ts.map +0 -1
- package/dist/utils/output-formatter.js +0 -338
- package/dist/utils/output-formatter.js.map +0 -1
|
@@ -1,78 +1,12 @@
|
|
|
1
|
-
import { describe, it, expect
|
|
2
|
-
import {
|
|
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
|
|
24
|
-
|
|
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
|
|
57
|
-
|
|
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
|
|
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
|
|
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
|
|
56
|
+
return CLASSIFICATION.BARREL;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
// 2. Detect type definition files
|
|
60
60
|
if (isTypeDefinition(node)) {
|
|
61
|
-
return
|
|
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
|
|
66
|
+
return CLASSIFICATION.NEXTJS_PAGE;
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// 4. Detect Lambda handlers
|
|
70
70
|
if (isLambdaHandler(node)) {
|
|
71
|
-
return
|
|
71
|
+
return CLASSIFICATION.LAMBDA_HANDLER;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// 5. Detect Service files
|
|
75
75
|
if (isServiceFile(node)) {
|
|
76
|
-
return
|
|
76
|
+
return CLASSIFICATION.SERVICE;
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
// 6. Detect Email templates
|
|
80
80
|
if (isEmailTemplate(node)) {
|
|
81
|
-
return
|
|
81
|
+
return CLASSIFICATION.EMAIL_TEMPLATE;
|
|
82
82
|
}
|
|
83
83
|
|
|
84
84
|
// 7. Detect Parser/Transformer files
|
|
85
85
|
if (isParserFile(node)) {
|
|
86
|
-
return
|
|
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
|
|
94
|
-
return
|
|
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
|
|
99
|
+
return CLASSIFICATION.UTILITY_MODULE;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
// 10. Detect Config/Schema files
|
|
103
103
|
if (isConfigFile(node)) {
|
|
104
|
-
return
|
|
104
|
+
return CLASSIFICATION.COHESIVE_MODULE;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
// 11. Detect Spoke modules in monorepo
|
|
108
108
|
if (isHubAndSpokeFile(node)) {
|
|
109
|
-
return
|
|
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
|
|
114
|
+
return CLASSIFICATION.COHESIVE_MODULE;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
if (domains.length > 1 && cohesionScore < 0.4) {
|
|
118
|
-
return
|
|
118
|
+
return CLASSIFICATION.MIXED_CONCERNS;
|
|
119
119
|
}
|
|
120
120
|
|
|
121
121
|
if (cohesionScore >= 0.7) {
|
|
122
|
-
return
|
|
122
|
+
return CLASSIFICATION.COHESIVE_MODULE;
|
|
123
123
|
}
|
|
124
124
|
|
|
125
|
-
return
|
|
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
|
|
144
|
+
case CLASSIFICATION.BOILERPLATE:
|
|
145
145
|
return 0.2; // Redundant indirection is low cohesion (architectural theater)
|
|
146
|
-
case
|
|
146
|
+
case CLASSIFICATION.BARREL:
|
|
147
147
|
return 1;
|
|
148
|
-
case
|
|
148
|
+
case CLASSIFICATION.TYPE_DEFINITION:
|
|
149
149
|
return 1;
|
|
150
|
-
case
|
|
150
|
+
case CLASSIFICATION.NEXTJS_PAGE:
|
|
151
151
|
return 1;
|
|
152
|
-
case
|
|
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
|
|
163
|
+
case CLASSIFICATION.SERVICE:
|
|
164
164
|
return Math.max(0.72, Math.min(1, baseCohesion + 0.3));
|
|
165
|
-
case
|
|
165
|
+
case CLASSIFICATION.LAMBDA_HANDLER:
|
|
166
166
|
return Math.max(0.75, Math.min(1, baseCohesion + 0.35));
|
|
167
|
-
case
|
|
167
|
+
case CLASSIFICATION.EMAIL_TEMPLATE:
|
|
168
168
|
return Math.max(0.72, Math.min(1, baseCohesion + 0.3));
|
|
169
|
-
case
|
|
169
|
+
case CLASSIFICATION.PARSER:
|
|
170
170
|
return Math.max(0.7, Math.min(1, baseCohesion + 0.3));
|
|
171
|
-
case
|
|
171
|
+
case CLASSIFICATION.SPOKE_MODULE:
|
|
172
172
|
return Math.max(baseCohesion, 0.6);
|
|
173
|
-
case
|
|
173
|
+
case CLASSIFICATION.COHESIVE_MODULE:
|
|
174
174
|
return Math.max(baseCohesion, 0.7);
|
|
175
|
-
case
|
|
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
|
|
247
|
+
case CLASSIFICATION.BOILERPLATE:
|
|
248
248
|
return baseFragmentation * 1.5; // Redundant barrels increase fragmentation
|
|
249
|
-
case
|
|
249
|
+
case CLASSIFICATION.BARREL:
|
|
250
250
|
return 0;
|
|
251
|
-
case
|
|
251
|
+
case CLASSIFICATION.TYPE_DEFINITION:
|
|
252
252
|
return 0;
|
|
253
|
-
case
|
|
254
|
-
case
|
|
255
|
-
case
|
|
256
|
-
case
|
|
257
|
-
case
|
|
258
|
-
case
|
|
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
|
|
260
|
+
case CLASSIFICATION.SPOKE_MODULE:
|
|
261
261
|
return baseFragmentation * 0.15; // Heavily discount intentional monorepo separation
|
|
262
|
-
case
|
|
262
|
+
case CLASSIFICATION.COHESIVE_MODULE:
|
|
263
263
|
return baseFragmentation * 0.3;
|
|
264
|
-
case
|
|
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
|
|
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 {
|
|
2
|
+
import { CONTEXT_ANALYZER_PROVIDER } from './provider';
|
|
3
3
|
|
|
4
4
|
// Register with global registry
|
|
5
|
-
ToolRegistry.register(
|
|
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
|
-
|
|
18
|
-
export
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
49
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"analyzer.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/analyzer.test.ts"],"names":[],"mappings":""}
|