@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
package/dist/metrics.d.ts
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { ExportInfo } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Calculate cohesion score (how related are exports in a file)
|
|
4
|
-
*/
|
|
5
|
-
export declare function calculateEnhancedCohesion(exports: ExportInfo[], filePath?: string, options?: {
|
|
6
|
-
coUsageMatrix?: Map<string, Map<string, number>>;
|
|
7
|
-
weights?: {
|
|
8
|
-
importBased?: number;
|
|
9
|
-
structural?: number;
|
|
10
|
-
domainBased?: number;
|
|
11
|
-
};
|
|
12
|
-
}): number;
|
|
13
|
-
/**
|
|
14
|
-
* Calculate structural cohesion for a file based on co-usage patterns.
|
|
15
|
-
*/
|
|
16
|
-
export declare function calculateStructuralCohesionFromCoUsage(file: string, coUsageMatrix?: Map<string, Map<string, number>>): number;
|
|
17
|
-
/**
|
|
18
|
-
* Calculate fragmentation score (how scattered is a domain)
|
|
19
|
-
*/
|
|
20
|
-
export declare function calculateFragmentation(files: string[], domain: string, options?: {
|
|
21
|
-
useLogScale?: boolean;
|
|
22
|
-
logBase?: number;
|
|
23
|
-
sharedImportRatio?: number;
|
|
24
|
-
dependencyCount?: number;
|
|
25
|
-
}): number;
|
|
26
|
-
/**
|
|
27
|
-
* Calculate path entropy for a set of files
|
|
28
|
-
*/
|
|
29
|
-
export declare function calculatePathEntropy(files: string[]): number;
|
|
30
|
-
/**
|
|
31
|
-
* Calculate directory-distance metric based on common ancestor depth
|
|
32
|
-
*/
|
|
33
|
-
export declare function calculateDirectoryDistance(files: string[]): number;
|
|
34
|
-
//# sourceMappingURL=metrics.d.ts.map
|
package/dist/metrics.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAG1C;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE,UAAU,EAAE,EACrB,QAAQ,CAAC,EAAE,MAAM,EACjB,OAAO,CAAC,EAAE;IACR,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjD,OAAO,CAAC,EAAE;QACR,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH,GACA,MAAM,CA4ER;AAED;;GAEG;AACH,wBAAgB,sCAAsC,CACpD,IAAI,EAAE,MAAM,EACZ,aAAa,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAC/C,MAAM,CAwBR;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,MAAM,EAAE,EACf,MAAM,EAAE,MAAM,EACd,OAAO,CAAC,EAAE;IACR,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,GACA,MAAM,CAuBR;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAqB5D;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CA0BlE"}
|
package/dist/metrics.js
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import { calculateImportSimilarity } from '@aiready/core';
|
|
2
|
-
import { isTestFile } from './ast-utils';
|
|
3
|
-
/**
|
|
4
|
-
* Calculate cohesion score (how related are exports in a file)
|
|
5
|
-
*/
|
|
6
|
-
export function calculateEnhancedCohesion(exports, filePath, options) {
|
|
7
|
-
if (exports.length <= 1)
|
|
8
|
-
return 1;
|
|
9
|
-
// Test files always have perfect cohesion by design
|
|
10
|
-
if (filePath && isTestFile(filePath))
|
|
11
|
-
return 1;
|
|
12
|
-
// 1. Domain-based cohesion using entropy
|
|
13
|
-
const domains = exports.map((e) => e.inferredDomain || 'unknown');
|
|
14
|
-
const domainCounts = new Map();
|
|
15
|
-
for (const d of domains)
|
|
16
|
-
domainCounts.set(d, (domainCounts.get(d) || 0) + 1);
|
|
17
|
-
// IF ALL DOMAINS MATCH, RETURN 1.0 IMMEDIATELY (Legacy test compatibility)
|
|
18
|
-
if (domainCounts.size === 1 && domains[0] !== 'unknown') {
|
|
19
|
-
if (!options?.weights)
|
|
20
|
-
return 1;
|
|
21
|
-
}
|
|
22
|
-
const probs = Array.from(domainCounts.values()).map((c) => c / exports.length);
|
|
23
|
-
let domainEntropy = 0;
|
|
24
|
-
for (const p of probs) {
|
|
25
|
-
if (p > 0)
|
|
26
|
-
domainEntropy -= p * Math.log2(p);
|
|
27
|
-
}
|
|
28
|
-
const maxEntropy = Math.log2(Math.max(2, domainCounts.size));
|
|
29
|
-
const domainScore = 1 - domainEntropy / maxEntropy;
|
|
30
|
-
// 2. Import-based cohesion
|
|
31
|
-
let importScoreTotal = 0;
|
|
32
|
-
let pairsWithData = 0;
|
|
33
|
-
let anyImportData = false;
|
|
34
|
-
for (let i = 0; i < exports.length; i++) {
|
|
35
|
-
for (let j = i + 1; j < exports.length; j++) {
|
|
36
|
-
const exp1Imports = exports[i].imports;
|
|
37
|
-
const exp2Imports = exports[j].imports;
|
|
38
|
-
if (exp1Imports || exp2Imports) {
|
|
39
|
-
anyImportData = true;
|
|
40
|
-
const sim = calculateImportSimilarity({ ...exports[i], imports: exp1Imports || [] }, { ...exports[j], imports: exp2Imports || [] });
|
|
41
|
-
importScoreTotal += sim;
|
|
42
|
-
pairsWithData++;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
const avgImportScore = pairsWithData > 0 ? importScoreTotal / pairsWithData : 0;
|
|
47
|
-
// Weighted average
|
|
48
|
-
let score = anyImportData
|
|
49
|
-
? domainScore * 0.4 + avgImportScore * 0.6
|
|
50
|
-
: domainScore;
|
|
51
|
-
if (anyImportData && score === 0 && domainScore === 0) {
|
|
52
|
-
score = 0.1;
|
|
53
|
-
}
|
|
54
|
-
// Structural boost
|
|
55
|
-
let structuralScore = 0;
|
|
56
|
-
for (const exp of exports) {
|
|
57
|
-
if (exp.dependencies && exp.dependencies.length > 0) {
|
|
58
|
-
structuralScore += 1;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
if (structuralScore > 0) {
|
|
62
|
-
score = Math.min(1, score + 0.1);
|
|
63
|
-
}
|
|
64
|
-
// Legacy fallback if no imports and domain Score was 1.0
|
|
65
|
-
if (!options?.weights && !anyImportData && domainCounts.size === 1)
|
|
66
|
-
return 1;
|
|
67
|
-
return score;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Calculate structural cohesion for a file based on co-usage patterns.
|
|
71
|
-
*/
|
|
72
|
-
export function calculateStructuralCohesionFromCoUsage(file, coUsageMatrix) {
|
|
73
|
-
if (!coUsageMatrix)
|
|
74
|
-
return 1;
|
|
75
|
-
const coUsages = coUsageMatrix.get(file);
|
|
76
|
-
if (!coUsages || coUsages.size === 0)
|
|
77
|
-
return 1;
|
|
78
|
-
let total = 0;
|
|
79
|
-
for (const count of coUsages.values())
|
|
80
|
-
total += count;
|
|
81
|
-
if (total === 0)
|
|
82
|
-
return 1;
|
|
83
|
-
const probs = [];
|
|
84
|
-
for (const count of coUsages.values()) {
|
|
85
|
-
if (count > 0)
|
|
86
|
-
probs.push(count / total);
|
|
87
|
-
}
|
|
88
|
-
if (probs.length <= 1)
|
|
89
|
-
return 1;
|
|
90
|
-
let entropy = 0;
|
|
91
|
-
for (const prob of probs) {
|
|
92
|
-
entropy -= prob * Math.log2(prob);
|
|
93
|
-
}
|
|
94
|
-
const maxEntropy = Math.log2(probs.length);
|
|
95
|
-
return maxEntropy > 0 ? 1 - entropy / maxEntropy : 1;
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Calculate fragmentation score (how scattered is a domain)
|
|
99
|
-
*/
|
|
100
|
-
export function calculateFragmentation(files, domain, options) {
|
|
101
|
-
if (files.length <= 1)
|
|
102
|
-
return 0;
|
|
103
|
-
const directories = new Set(files.map((f) => f.split('/').slice(0, -1).join('/')));
|
|
104
|
-
const uniqueDirs = directories.size;
|
|
105
|
-
let score = options?.useLogScale
|
|
106
|
-
? uniqueDirs <= 1
|
|
107
|
-
? 0
|
|
108
|
-
: Math.log(uniqueDirs) /
|
|
109
|
-
Math.log(options.logBase || Math.E) /
|
|
110
|
-
(Math.log(files.length) / Math.log(options.logBase || Math.E))
|
|
111
|
-
: (uniqueDirs - 1) / (files.length - 1);
|
|
112
|
-
// Coupling Discount
|
|
113
|
-
if (options?.sharedImportRatio && options.sharedImportRatio > 0.5) {
|
|
114
|
-
const discount = (options.sharedImportRatio - 0.5) * 0.4;
|
|
115
|
-
score = score * (1 - discount);
|
|
116
|
-
}
|
|
117
|
-
return score;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Calculate path entropy for a set of files
|
|
121
|
-
*/
|
|
122
|
-
export function calculatePathEntropy(files) {
|
|
123
|
-
if (!files || files.length === 0)
|
|
124
|
-
return 0;
|
|
125
|
-
const dirCounts = new Map();
|
|
126
|
-
for (const f of files) {
|
|
127
|
-
const dir = f.split('/').slice(0, -1).join('/') || '.';
|
|
128
|
-
dirCounts.set(dir, (dirCounts.get(dir) || 0) + 1);
|
|
129
|
-
}
|
|
130
|
-
const counts = Array.from(dirCounts.values());
|
|
131
|
-
if (counts.length <= 1)
|
|
132
|
-
return 0;
|
|
133
|
-
const total = counts.reduce((s, v) => s + v, 0);
|
|
134
|
-
let entropy = 0;
|
|
135
|
-
for (const count of counts) {
|
|
136
|
-
const prob = count / total;
|
|
137
|
-
entropy -= prob * Math.log2(prob);
|
|
138
|
-
}
|
|
139
|
-
const maxEntropy = Math.log2(counts.length);
|
|
140
|
-
return maxEntropy > 0 ? entropy / maxEntropy : 0;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Calculate directory-distance metric based on common ancestor depth
|
|
144
|
-
*/
|
|
145
|
-
export function calculateDirectoryDistance(files) {
|
|
146
|
-
if (!files || files.length <= 1)
|
|
147
|
-
return 0;
|
|
148
|
-
const pathSegments = (p) => p.split('/').filter(Boolean);
|
|
149
|
-
const commonAncestorDepth = (a, b) => {
|
|
150
|
-
const minLen = Math.min(a.length, b.length);
|
|
151
|
-
let i = 0;
|
|
152
|
-
while (i < minLen && a[i] === b[i])
|
|
153
|
-
i++;
|
|
154
|
-
return i;
|
|
155
|
-
};
|
|
156
|
-
let totalNormalized = 0;
|
|
157
|
-
let comparisons = 0;
|
|
158
|
-
for (let i = 0; i < files.length; i++) {
|
|
159
|
-
for (let j = i + 1; j < files.length; j++) {
|
|
160
|
-
const segA = pathSegments(files[i]);
|
|
161
|
-
const segB = pathSegments(files[j]);
|
|
162
|
-
const shared = commonAncestorDepth(segA, segB);
|
|
163
|
-
const maxDepth = Math.max(segA.length, segB.length);
|
|
164
|
-
totalNormalized += 1 - (maxDepth > 0 ? shared / maxDepth : 0);
|
|
165
|
-
comparisons++;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return comparisons > 0 ? totalNormalized / comparisons : 0;
|
|
169
|
-
}
|
|
170
|
-
//# sourceMappingURL=metrics.js.map
|
package/dist/metrics.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../src/metrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,eAAe,CAAC;AAE1D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;GAEG;AACH,MAAM,UAAU,yBAAyB,CACvC,OAAqB,EACrB,Q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,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC1C,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACpC,MAAM,IAAI,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;YACpC,MAAM,MAAM,GAAG,mBAAmB,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;YAC/C,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;YACpD,eAAe,IAAI,CAAC,GAAG,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC9D,WAAW,EAAE,CAAC;QAChB,CAAC;IACH,CAAC;IAED,OAAO,WAAW,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;AAC7D,CAAC"}
|
package/dist/provider.d.ts
DELETED
package/dist/provider.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EASb,MAAM,eAAe,CAAC;AAMvB;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,YA8CrC,CAAC"}
|
package/dist/provider.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { ToolName, IssueType, SpokeOutputSchema, } from '@aiready/core';
|
|
2
|
-
import { analyzeContext } from './analyzer';
|
|
3
|
-
import { generateSummary } from './summary';
|
|
4
|
-
import { calculateContextScore } from './scoring';
|
|
5
|
-
/**
|
|
6
|
-
* Context Analyzer Tool Provider
|
|
7
|
-
*/
|
|
8
|
-
export const ContextAnalyzerProvider = {
|
|
9
|
-
id: ToolName.ContextAnalyzer,
|
|
10
|
-
alias: ['context', 'fragmentation', 'budget'],
|
|
11
|
-
async analyze(options) {
|
|
12
|
-
const results = await analyzeContext(options);
|
|
13
|
-
const summary = generateSummary(results, options);
|
|
14
|
-
// Normalize to SpokeOutput format
|
|
15
|
-
const normalizedResults = results.map((r) => ({
|
|
16
|
-
fileName: r.file,
|
|
17
|
-
issues: r.issues.map((msg) => ({
|
|
18
|
-
type: IssueType.ContextFragmentation,
|
|
19
|
-
severity: r.severity,
|
|
20
|
-
message: msg,
|
|
21
|
-
location: { file: r.file, line: 1 },
|
|
22
|
-
suggestion: r.recommendations[0],
|
|
23
|
-
})),
|
|
24
|
-
metrics: {
|
|
25
|
-
tokenCost: r.tokenCost,
|
|
26
|
-
complexityScore: r.importDepth,
|
|
27
|
-
// Map other context-specific metrics if needed
|
|
28
|
-
},
|
|
29
|
-
}));
|
|
30
|
-
return SpokeOutputSchema.parse({
|
|
31
|
-
results: normalizedResults,
|
|
32
|
-
summary: {
|
|
33
|
-
...summary,
|
|
34
|
-
},
|
|
35
|
-
metadata: {
|
|
36
|
-
toolName: ToolName.ContextAnalyzer,
|
|
37
|
-
version: '0.17.5',
|
|
38
|
-
timestamp: new Date().toISOString(),
|
|
39
|
-
},
|
|
40
|
-
});
|
|
41
|
-
},
|
|
42
|
-
score(output, options) {
|
|
43
|
-
const summary = output.summary;
|
|
44
|
-
return calculateContextScore(summary, options.costConfig);
|
|
45
|
-
},
|
|
46
|
-
defaultWeight: 19,
|
|
47
|
-
};
|
|
48
|
-
//# sourceMappingURL=provider.js.map
|
package/dist/provider.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAMR,SAAS,EACT,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AA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AC,WAAW,EAAE;aACpC;SACF,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,MAAmB,EAAE,OAAoB;QAC7C,MAAM,OAAO,GAAG,MAAM,CAAC,OAAc,CAAC;QACtC,OAAO,qBAAqB,CAAC,OAAO,EAAG,OAAe,CAAC,UAAU,CAAC,CAAC;IACrE,CAAC;IAED,aAAa,EAAE,EAAE;CAClB,CAAC"}
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
calculateImportDepthFromEdges,
|
|
3
|
-
detectGraphCyclesFromFile
|
|
4
|
-
} from "./chunk-64U3PNO3.mjs";
|
|
5
|
-
|
|
6
|
-
// src/analyzers/python-context.ts
|
|
7
|
-
import { getParser, estimateTokens } from "@aiready/core";
|
|
8
|
-
import { resolve, relative, dirname, join } from "path";
|
|
9
|
-
import fs from "fs";
|
|
10
|
-
async function analyzePythonContext(files, rootDir) {
|
|
11
|
-
const results = [];
|
|
12
|
-
const parser = getParser("dummy.py");
|
|
13
|
-
if (!parser) {
|
|
14
|
-
console.warn("Python parser not available");
|
|
15
|
-
return results;
|
|
16
|
-
}
|
|
17
|
-
const pythonFiles = files.filter((f) => f.toLowerCase().endsWith(".py"));
|
|
18
|
-
void relative;
|
|
19
|
-
void join;
|
|
20
|
-
const dependencyGraph = await buildPythonDependencyGraph(
|
|
21
|
-
pythonFiles,
|
|
22
|
-
rootDir
|
|
23
|
-
);
|
|
24
|
-
for (const file of pythonFiles) {
|
|
25
|
-
try {
|
|
26
|
-
const code = await fs.promises.readFile(file, "utf-8");
|
|
27
|
-
const result = parser.parse(code, file);
|
|
28
|
-
const imports = result.imports.map((imp) => ({
|
|
29
|
-
source: imp.source,
|
|
30
|
-
specifiers: imp.specifiers,
|
|
31
|
-
isRelative: imp.source.startsWith("."),
|
|
32
|
-
resolvedPath: resolvePythonImport(file, imp.source, rootDir)
|
|
33
|
-
}));
|
|
34
|
-
const exports = result.exports.map((exp) => ({
|
|
35
|
-
name: exp.name,
|
|
36
|
-
type: exp.type
|
|
37
|
-
}));
|
|
38
|
-
const linesOfCode = code.split("\n").length;
|
|
39
|
-
const importDepth = calculateImportDepthFromEdges(
|
|
40
|
-
file,
|
|
41
|
-
dependencyGraph,
|
|
42
|
-
/* @__PURE__ */ new Set()
|
|
43
|
-
);
|
|
44
|
-
const contextBudget = estimateContextBudget(
|
|
45
|
-
code,
|
|
46
|
-
imports,
|
|
47
|
-
dependencyGraph
|
|
48
|
-
);
|
|
49
|
-
const cohesion = calculatePythonCohesion(exports, imports);
|
|
50
|
-
const circularDependencies = detectGraphCyclesFromFile(
|
|
51
|
-
file,
|
|
52
|
-
dependencyGraph
|
|
53
|
-
).map((cycle) => cycle.join(" -> "));
|
|
54
|
-
results.push({
|
|
55
|
-
file,
|
|
56
|
-
importDepth,
|
|
57
|
-
contextBudget,
|
|
58
|
-
cohesion,
|
|
59
|
-
imports,
|
|
60
|
-
exports,
|
|
61
|
-
metrics: {
|
|
62
|
-
linesOfCode,
|
|
63
|
-
importCount: imports.length,
|
|
64
|
-
exportCount: exports.length,
|
|
65
|
-
circularDependencies
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
} catch (error) {
|
|
69
|
-
console.warn(`Failed to analyze ${file}:`, error);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return results;
|
|
73
|
-
}
|
|
74
|
-
async function buildPythonDependencyGraph(files, rootDir) {
|
|
75
|
-
const graph = /* @__PURE__ */ new Map();
|
|
76
|
-
const parser = getParser("dummy.py");
|
|
77
|
-
if (!parser) return graph;
|
|
78
|
-
for (const file of files) {
|
|
79
|
-
try {
|
|
80
|
-
const code = await fs.promises.readFile(file, "utf-8");
|
|
81
|
-
const result = parser.parse(code, file);
|
|
82
|
-
const dependencies = /* @__PURE__ */ new Set();
|
|
83
|
-
for (const imp of result.imports) {
|
|
84
|
-
const resolved = resolvePythonImport(file, imp.source, rootDir);
|
|
85
|
-
if (resolved && files.includes(resolved)) {
|
|
86
|
-
dependencies.add(resolved);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
graph.set(file, dependencies);
|
|
90
|
-
} catch (error) {
|
|
91
|
-
void error;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return graph;
|
|
95
|
-
}
|
|
96
|
-
function resolvePythonImport(fromFile, importPath, rootDir) {
|
|
97
|
-
const dir = dirname(fromFile);
|
|
98
|
-
if (importPath.startsWith(".")) {
|
|
99
|
-
const parts = importPath.split(".");
|
|
100
|
-
let upCount = 0;
|
|
101
|
-
while (parts[0] === "") {
|
|
102
|
-
upCount++;
|
|
103
|
-
parts.shift();
|
|
104
|
-
}
|
|
105
|
-
let targetDir = dir;
|
|
106
|
-
for (let i = 0; i < upCount - 1; i++) {
|
|
107
|
-
targetDir = dirname(targetDir);
|
|
108
|
-
}
|
|
109
|
-
const modulePath = parts.join("/");
|
|
110
|
-
const possiblePaths = [
|
|
111
|
-
resolve(targetDir, `${modulePath}.py`),
|
|
112
|
-
resolve(targetDir, modulePath, "__init__.py")
|
|
113
|
-
];
|
|
114
|
-
for (const path of possiblePaths) {
|
|
115
|
-
if (fs.existsSync(path)) {
|
|
116
|
-
return path;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
} else {
|
|
120
|
-
const modulePath = importPath.replace(/\./g, "/");
|
|
121
|
-
const possiblePaths = [
|
|
122
|
-
resolve(rootDir, `${modulePath}.py`),
|
|
123
|
-
resolve(rootDir, modulePath, "__init__.py")
|
|
124
|
-
];
|
|
125
|
-
for (const path of possiblePaths) {
|
|
126
|
-
if (fs.existsSync(path)) {
|
|
127
|
-
return path;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
return void 0;
|
|
132
|
-
}
|
|
133
|
-
function estimateContextBudget(code, imports, dependencyGraph) {
|
|
134
|
-
void dependencyGraph;
|
|
135
|
-
let budget = estimateTokens(code);
|
|
136
|
-
const avgTokensPerDep = 500;
|
|
137
|
-
budget += imports.length * avgTokensPerDep;
|
|
138
|
-
return budget;
|
|
139
|
-
}
|
|
140
|
-
function calculatePythonCohesion(exports, imports) {
|
|
141
|
-
if (exports.length === 0) return 1;
|
|
142
|
-
const exportCount = exports.length;
|
|
143
|
-
const importCount = imports.length;
|
|
144
|
-
let cohesion = 1;
|
|
145
|
-
if (exportCount > 10) {
|
|
146
|
-
cohesion *= 0.6;
|
|
147
|
-
} else if (exportCount > 5) {
|
|
148
|
-
cohesion *= 0.8;
|
|
149
|
-
}
|
|
150
|
-
if (exportCount > 0) {
|
|
151
|
-
const ratio = importCount / exportCount;
|
|
152
|
-
if (ratio > 2) {
|
|
153
|
-
cohesion *= 1.1;
|
|
154
|
-
} else if (ratio < 0.5) {
|
|
155
|
-
cohesion *= 0.9;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
return Math.min(1, Math.max(0, cohesion));
|
|
159
|
-
}
|
|
160
|
-
export {
|
|
161
|
-
analyzePythonContext
|
|
162
|
-
};
|