@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.
- package/.turbo/turbo-build.log +33 -32
- package/.turbo/turbo-format-check.log +2 -2
- package/.turbo/turbo-lint.log +9 -1
- package/.turbo/turbo-test.log +23 -23
- package/.turbo/turbo-type-check.log +1 -1
- 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/chunk-4U4LDWGF.mjs
DELETED
|
@@ -1,360 +0,0 @@
|
|
|
1
|
-
// src/utils/string-utils.ts
|
|
2
|
-
function singularize(word) {
|
|
3
|
-
const irregulars = {
|
|
4
|
-
people: "person",
|
|
5
|
-
children: "child",
|
|
6
|
-
men: "man",
|
|
7
|
-
women: "woman"
|
|
8
|
-
};
|
|
9
|
-
if (irregulars[word]) return irregulars[word];
|
|
10
|
-
if (word.endsWith("ies")) return word.slice(0, -3) + "y";
|
|
11
|
-
if (word.endsWith("ses")) return word.slice(0, -2);
|
|
12
|
-
if (word.endsWith("s") && word.length > 3) return word.slice(0, -1);
|
|
13
|
-
return word;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// src/semantic/domain-inference.ts
|
|
17
|
-
function calculateDomainConfidence(signals) {
|
|
18
|
-
const weights = {
|
|
19
|
-
coUsage: 0.35,
|
|
20
|
-
typeReference: 0.3,
|
|
21
|
-
exportName: 0.15,
|
|
22
|
-
importPath: 0.1,
|
|
23
|
-
folderStructure: 0.1
|
|
24
|
-
};
|
|
25
|
-
let confidence = 0;
|
|
26
|
-
if (signals.coUsage) confidence += weights.coUsage;
|
|
27
|
-
if (signals.typeReference) confidence += weights.typeReference;
|
|
28
|
-
if (signals.exportName) confidence += weights.exportName;
|
|
29
|
-
if (signals.importPath) confidence += weights.importPath;
|
|
30
|
-
if (signals.folderStructure) confidence += weights.folderStructure;
|
|
31
|
-
return confidence;
|
|
32
|
-
}
|
|
33
|
-
function inferDomainFromSemantics(file, exportName, graph, coUsageMatrix, typeGraph, exportTypeRefs) {
|
|
34
|
-
const domainSignals = /* @__PURE__ */ new Map();
|
|
35
|
-
const coUsages = coUsageMatrix.get(file) || /* @__PURE__ */ new Map();
|
|
36
|
-
const strongCoUsages = Array.from(coUsages.entries()).filter(([, count]) => count >= 3).map(([coFile]) => coFile);
|
|
37
|
-
for (const coFile of strongCoUsages) {
|
|
38
|
-
const coNode = graph.nodes.get(coFile);
|
|
39
|
-
if (coNode) {
|
|
40
|
-
for (const exp of coNode.exports) {
|
|
41
|
-
if (exp.inferredDomain && exp.inferredDomain !== "unknown") {
|
|
42
|
-
const domain = exp.inferredDomain;
|
|
43
|
-
if (!domainSignals.has(domain)) {
|
|
44
|
-
domainSignals.set(domain, {
|
|
45
|
-
coUsage: false,
|
|
46
|
-
typeReference: false,
|
|
47
|
-
exportName: false,
|
|
48
|
-
importPath: false,
|
|
49
|
-
folderStructure: false
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
domainSignals.get(domain).coUsage = true;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
if (exportTypeRefs) {
|
|
58
|
-
for (const typeRef of exportTypeRefs) {
|
|
59
|
-
const filesWithType = typeGraph.get(typeRef);
|
|
60
|
-
if (filesWithType) {
|
|
61
|
-
for (const typeFile of filesWithType) {
|
|
62
|
-
if (typeFile === file) continue;
|
|
63
|
-
const typeNode = graph.nodes.get(typeFile);
|
|
64
|
-
if (typeNode) {
|
|
65
|
-
for (const exp of typeNode.exports) {
|
|
66
|
-
if (exp.inferredDomain && exp.inferredDomain !== "unknown") {
|
|
67
|
-
const domain = exp.inferredDomain;
|
|
68
|
-
if (!domainSignals.has(domain)) {
|
|
69
|
-
domainSignals.set(domain, {
|
|
70
|
-
coUsage: false,
|
|
71
|
-
typeReference: false,
|
|
72
|
-
exportName: false,
|
|
73
|
-
importPath: false,
|
|
74
|
-
folderStructure: false
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
domainSignals.get(domain).typeReference = true;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const assignments = [];
|
|
86
|
-
for (const [domain, signals] of domainSignals) {
|
|
87
|
-
const confidence = calculateDomainConfidence(signals);
|
|
88
|
-
if (confidence >= 0.3) assignments.push({ domain, confidence, signals });
|
|
89
|
-
}
|
|
90
|
-
assignments.sort((a, b) => b.confidence - a.confidence);
|
|
91
|
-
return assignments;
|
|
92
|
-
}
|
|
93
|
-
function extractExports(content, filePath, domainOptions, fileImports) {
|
|
94
|
-
const exports = [];
|
|
95
|
-
const patterns = [
|
|
96
|
-
/export\s+function\s+(\w+)/g,
|
|
97
|
-
/export\s+class\s+(\w+)/g,
|
|
98
|
-
/export\s+const\s+(\w+)/g,
|
|
99
|
-
/export\s+type\s+(\w+)/g,
|
|
100
|
-
/export\s+interface\s+(\w+)/g,
|
|
101
|
-
/export\s+default/g
|
|
102
|
-
];
|
|
103
|
-
const types = [
|
|
104
|
-
"function",
|
|
105
|
-
"class",
|
|
106
|
-
"const",
|
|
107
|
-
"type",
|
|
108
|
-
"interface",
|
|
109
|
-
"default"
|
|
110
|
-
];
|
|
111
|
-
patterns.forEach((pattern, index) => {
|
|
112
|
-
let match;
|
|
113
|
-
while ((match = pattern.exec(content)) !== null) {
|
|
114
|
-
const name = match[1] || "default";
|
|
115
|
-
const type = types[index];
|
|
116
|
-
const inferredDomain = inferDomain(
|
|
117
|
-
name,
|
|
118
|
-
filePath,
|
|
119
|
-
domainOptions,
|
|
120
|
-
fileImports
|
|
121
|
-
);
|
|
122
|
-
exports.push({ name, type, inferredDomain });
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
return exports;
|
|
126
|
-
}
|
|
127
|
-
function inferDomain(name, filePath, domainOptions, fileImports) {
|
|
128
|
-
const lower = name.toLowerCase();
|
|
129
|
-
const tokens = Array.from(
|
|
130
|
-
new Set(
|
|
131
|
-
lower.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[^a-z0-9]+/gi, " ").split(" ").filter(Boolean)
|
|
132
|
-
)
|
|
133
|
-
);
|
|
134
|
-
const defaultKeywords = [
|
|
135
|
-
"authentication",
|
|
136
|
-
"authorization",
|
|
137
|
-
"payment",
|
|
138
|
-
"invoice",
|
|
139
|
-
"customer",
|
|
140
|
-
"product",
|
|
141
|
-
"order",
|
|
142
|
-
"cart",
|
|
143
|
-
"user",
|
|
144
|
-
"admin",
|
|
145
|
-
"repository",
|
|
146
|
-
"controller",
|
|
147
|
-
"service",
|
|
148
|
-
"config",
|
|
149
|
-
"model",
|
|
150
|
-
"view",
|
|
151
|
-
"auth"
|
|
152
|
-
];
|
|
153
|
-
const domainKeywords = domainOptions?.domainKeywords?.length ? [...domainOptions.domainKeywords, ...defaultKeywords] : defaultKeywords;
|
|
154
|
-
for (const keyword of domainKeywords) {
|
|
155
|
-
if (tokens.includes(keyword)) return keyword;
|
|
156
|
-
}
|
|
157
|
-
for (const keyword of domainKeywords) {
|
|
158
|
-
if (lower.includes(keyword)) return keyword;
|
|
159
|
-
}
|
|
160
|
-
if (fileImports) {
|
|
161
|
-
for (const importPath of fileImports) {
|
|
162
|
-
const segments = importPath.split("/");
|
|
163
|
-
for (const segment of segments) {
|
|
164
|
-
const segLower = segment.toLowerCase();
|
|
165
|
-
const singularSegment = singularize(segLower);
|
|
166
|
-
for (const keyword of domainKeywords) {
|
|
167
|
-
if (singularSegment === keyword || segLower === keyword || segLower.includes(keyword))
|
|
168
|
-
return keyword;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
if (filePath) {
|
|
174
|
-
const segments = filePath.split("/");
|
|
175
|
-
for (const segment of segments) {
|
|
176
|
-
const segLower = segment.toLowerCase();
|
|
177
|
-
const singularSegment = singularize(segLower);
|
|
178
|
-
for (const keyword of domainKeywords) {
|
|
179
|
-
if (singularSegment === keyword || segLower === keyword) return keyword;
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return "unknown";
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
// src/metrics.ts
|
|
187
|
-
import { calculateImportSimilarity } from "@aiready/core";
|
|
188
|
-
|
|
189
|
-
// src/ast-utils.ts
|
|
190
|
-
import { parseFileExports } from "@aiready/core";
|
|
191
|
-
async function extractExportsWithAST(content, filePath, domainOptions, fileImports) {
|
|
192
|
-
try {
|
|
193
|
-
const { exports: astExports } = await parseFileExports(content, filePath);
|
|
194
|
-
if (astExports.length === 0 && !isTestFile(filePath)) {
|
|
195
|
-
return extractExports(content, filePath, domainOptions, fileImports);
|
|
196
|
-
}
|
|
197
|
-
return astExports.map((exp) => ({
|
|
198
|
-
name: exp.name,
|
|
199
|
-
type: exp.type,
|
|
200
|
-
inferredDomain: inferDomain(
|
|
201
|
-
exp.name,
|
|
202
|
-
filePath,
|
|
203
|
-
domainOptions,
|
|
204
|
-
fileImports
|
|
205
|
-
),
|
|
206
|
-
imports: exp.imports,
|
|
207
|
-
dependencies: exp.dependencies,
|
|
208
|
-
typeReferences: exp.typeReferences
|
|
209
|
-
}));
|
|
210
|
-
} catch {
|
|
211
|
-
return extractExports(content, filePath, domainOptions, fileImports);
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
function isTestFile(filePath) {
|
|
215
|
-
const lower = filePath.toLowerCase();
|
|
216
|
-
return lower.includes(".test.") || lower.includes(".spec.") || lower.includes("/__tests__/") || lower.includes("/tests/") || lower.includes("/test/") || lower.includes("test-") || lower.includes("-test") || lower.includes("/__mocks__/") || lower.includes("/mocks/") || lower.includes("/fixtures/") || lower.includes(".mock.") || lower.includes(".fixture.") || lower.includes("/test-utils/");
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/metrics.ts
|
|
220
|
-
function calculateEnhancedCohesion(exports, filePath, options) {
|
|
221
|
-
if (exports.length <= 1) return 1;
|
|
222
|
-
if (filePath && isTestFile(filePath)) return 1;
|
|
223
|
-
const domains = exports.map((e) => e.inferredDomain || "unknown");
|
|
224
|
-
const domainCounts = /* @__PURE__ */ new Map();
|
|
225
|
-
for (const domain of domains)
|
|
226
|
-
domainCounts.set(domain, (domainCounts.get(domain) || 0) + 1);
|
|
227
|
-
if (domainCounts.size === 1 && domains[0] !== "unknown") {
|
|
228
|
-
if (!options?.weights) return 1;
|
|
229
|
-
}
|
|
230
|
-
const probs = Array.from(domainCounts.values()).map(
|
|
231
|
-
(count) => count / exports.length
|
|
232
|
-
);
|
|
233
|
-
let domainEntropy = 0;
|
|
234
|
-
for (const prob of probs) {
|
|
235
|
-
if (prob > 0) domainEntropy -= prob * Math.log2(prob);
|
|
236
|
-
}
|
|
237
|
-
const maxEntropy = Math.log2(Math.max(2, domainCounts.size));
|
|
238
|
-
const domainScore = 1 - domainEntropy / maxEntropy;
|
|
239
|
-
let importScoreTotal = 0;
|
|
240
|
-
let pairsWithData = 0;
|
|
241
|
-
let anyImportData = false;
|
|
242
|
-
for (let i = 0; i < exports.length; i++) {
|
|
243
|
-
for (let j = i + 1; j < exports.length; j++) {
|
|
244
|
-
const exp1Imports = exports[i].imports;
|
|
245
|
-
const exp2Imports = exports[j].imports;
|
|
246
|
-
if (exp1Imports || exp2Imports) {
|
|
247
|
-
anyImportData = true;
|
|
248
|
-
const sim = calculateImportSimilarity(
|
|
249
|
-
{ ...exports[i], imports: exp1Imports || [] },
|
|
250
|
-
{ ...exports[j], imports: exp2Imports || [] }
|
|
251
|
-
);
|
|
252
|
-
importScoreTotal += sim;
|
|
253
|
-
pairsWithData++;
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
const avgImportScore = pairsWithData > 0 ? importScoreTotal / pairsWithData : 0;
|
|
258
|
-
let score = anyImportData ? domainScore * 0.4 + avgImportScore * 0.6 : domainScore;
|
|
259
|
-
if (anyImportData && score === 0 && domainScore === 0) {
|
|
260
|
-
score = 0.1;
|
|
261
|
-
}
|
|
262
|
-
let structuralScore = 0;
|
|
263
|
-
for (const exp of exports) {
|
|
264
|
-
if (exp.dependencies && exp.dependencies.length > 0) {
|
|
265
|
-
structuralScore += 1;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
if (structuralScore > 0) {
|
|
269
|
-
score = Math.min(1, score + 0.1);
|
|
270
|
-
}
|
|
271
|
-
if (!options?.weights && !anyImportData && domainCounts.size === 1) return 1;
|
|
272
|
-
return score;
|
|
273
|
-
}
|
|
274
|
-
function calculateStructuralCohesionFromCoUsage(file, coUsageMatrix) {
|
|
275
|
-
if (!coUsageMatrix) return 1;
|
|
276
|
-
const coUsages = coUsageMatrix.get(file);
|
|
277
|
-
if (!coUsages || coUsages.size === 0) return 1;
|
|
278
|
-
let total = 0;
|
|
279
|
-
for (const count of coUsages.values()) total += count;
|
|
280
|
-
if (total === 0) return 1;
|
|
281
|
-
const probs = [];
|
|
282
|
-
for (const count of coUsages.values()) {
|
|
283
|
-
if (count > 0) probs.push(count / total);
|
|
284
|
-
}
|
|
285
|
-
if (probs.length <= 1) return 1;
|
|
286
|
-
let entropy = 0;
|
|
287
|
-
for (const prob of probs) {
|
|
288
|
-
entropy -= prob * Math.log2(prob);
|
|
289
|
-
}
|
|
290
|
-
const maxEntropy = Math.log2(probs.length);
|
|
291
|
-
return maxEntropy > 0 ? 1 - entropy / maxEntropy : 1;
|
|
292
|
-
}
|
|
293
|
-
function calculateFragmentation(files, domain, options) {
|
|
294
|
-
if (files.length <= 1) return 0;
|
|
295
|
-
const directories = new Set(
|
|
296
|
-
files.map((file) => file.split("/").slice(0, -1).join("/"))
|
|
297
|
-
);
|
|
298
|
-
const uniqueDirs = directories.size;
|
|
299
|
-
let score = options?.useLogScale ? uniqueDirs <= 1 ? 0 : Math.log(uniqueDirs) / Math.log(options.logBase || Math.E) / (Math.log(files.length) / Math.log(options.logBase || Math.E)) : (uniqueDirs - 1) / (files.length - 1);
|
|
300
|
-
if (options?.sharedImportRatio && options.sharedImportRatio > 0.5) {
|
|
301
|
-
const discount = (options.sharedImportRatio - 0.5) * 0.4;
|
|
302
|
-
score = score * (1 - discount);
|
|
303
|
-
}
|
|
304
|
-
return score;
|
|
305
|
-
}
|
|
306
|
-
function calculatePathEntropy(files) {
|
|
307
|
-
if (!files || files.length === 0) return 0;
|
|
308
|
-
const dirCounts = /* @__PURE__ */ new Map();
|
|
309
|
-
for (const file of files) {
|
|
310
|
-
const dir = file.split("/").slice(0, -1).join("/") || ".";
|
|
311
|
-
dirCounts.set(dir, (dirCounts.get(dir) || 0) + 1);
|
|
312
|
-
}
|
|
313
|
-
const counts = Array.from(dirCounts.values());
|
|
314
|
-
if (counts.length <= 1) return 0;
|
|
315
|
-
const total = counts.reduce((sum, value) => sum + value, 0);
|
|
316
|
-
let entropy = 0;
|
|
317
|
-
for (const count of counts) {
|
|
318
|
-
const prob = count / total;
|
|
319
|
-
entropy -= prob * Math.log2(prob);
|
|
320
|
-
}
|
|
321
|
-
const maxEntropy = Math.log2(counts.length);
|
|
322
|
-
return maxEntropy > 0 ? entropy / maxEntropy : 0;
|
|
323
|
-
}
|
|
324
|
-
function calculateDirectoryDistance(files) {
|
|
325
|
-
if (!files || files.length <= 1) return 0;
|
|
326
|
-
const pathSegments = (pathStr) => pathStr.split("/").filter(Boolean);
|
|
327
|
-
const commonAncestorDepth = (pathA, pathB) => {
|
|
328
|
-
const minLen = Math.min(pathA.length, pathB.length);
|
|
329
|
-
let i = 0;
|
|
330
|
-
while (i < minLen && pathA[i] === pathB[i]) i++;
|
|
331
|
-
return i;
|
|
332
|
-
};
|
|
333
|
-
let totalNormalized = 0;
|
|
334
|
-
let comparisons = 0;
|
|
335
|
-
for (let i = 0; i < files.length; i++) {
|
|
336
|
-
for (let j = i + 1; j < files.length; j++) {
|
|
337
|
-
const segA = pathSegments(files[i]);
|
|
338
|
-
const segB = pathSegments(files[j]);
|
|
339
|
-
const shared = commonAncestorDepth(segA, segB);
|
|
340
|
-
const maxDepth = Math.max(segA.length, segB.length);
|
|
341
|
-
totalNormalized += 1 - (maxDepth > 0 ? shared / maxDepth : 0);
|
|
342
|
-
comparisons++;
|
|
343
|
-
}
|
|
344
|
-
}
|
|
345
|
-
return comparisons > 0 ? totalNormalized / comparisons : 0;
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
export {
|
|
349
|
-
singularize,
|
|
350
|
-
calculateDomainConfidence,
|
|
351
|
-
inferDomainFromSemantics,
|
|
352
|
-
extractExports,
|
|
353
|
-
inferDomain,
|
|
354
|
-
extractExportsWithAST,
|
|
355
|
-
calculateEnhancedCohesion,
|
|
356
|
-
calculateStructuralCohesionFromCoUsage,
|
|
357
|
-
calculateFragmentation,
|
|
358
|
-
calculatePathEntropy,
|
|
359
|
-
calculateDirectoryDistance
|
|
360
|
-
};
|