@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,203 +0,0 @@
|
|
|
1
|
-
// src/analyzers/python-context.ts
|
|
2
|
-
import { getParser, estimateTokens } from "@aiready/core";
|
|
3
|
-
import { resolve, relative, dirname, join } from "path";
|
|
4
|
-
import fs from "fs";
|
|
5
|
-
async function analyzePythonContext(files, rootDir) {
|
|
6
|
-
const results = [];
|
|
7
|
-
const parser = getParser("dummy.py");
|
|
8
|
-
if (!parser) {
|
|
9
|
-
console.warn("Python parser not available");
|
|
10
|
-
return results;
|
|
11
|
-
}
|
|
12
|
-
const pythonFiles = files.filter((f) => f.toLowerCase().endsWith(".py"));
|
|
13
|
-
void relative;
|
|
14
|
-
void join;
|
|
15
|
-
const dependencyGraph = await buildPythonDependencyGraph(
|
|
16
|
-
pythonFiles,
|
|
17
|
-
rootDir
|
|
18
|
-
);
|
|
19
|
-
for (const file of pythonFiles) {
|
|
20
|
-
try {
|
|
21
|
-
const code = await fs.promises.readFile(file, "utf-8");
|
|
22
|
-
const result = parser.parse(code, file);
|
|
23
|
-
const imports = result.imports.map((imp) => ({
|
|
24
|
-
source: imp.source,
|
|
25
|
-
specifiers: imp.specifiers,
|
|
26
|
-
isRelative: imp.source.startsWith("."),
|
|
27
|
-
resolvedPath: resolvePythonImport(file, imp.source, rootDir)
|
|
28
|
-
}));
|
|
29
|
-
const exports = result.exports.map((exp) => ({
|
|
30
|
-
name: exp.name,
|
|
31
|
-
type: exp.type
|
|
32
|
-
}));
|
|
33
|
-
const linesOfCode = code.split("\n").length;
|
|
34
|
-
const importDepth = await calculatePythonImportDepth(
|
|
35
|
-
file,
|
|
36
|
-
dependencyGraph,
|
|
37
|
-
/* @__PURE__ */ new Set()
|
|
38
|
-
);
|
|
39
|
-
const contextBudget = estimateContextBudget(
|
|
40
|
-
code,
|
|
41
|
-
imports,
|
|
42
|
-
dependencyGraph
|
|
43
|
-
);
|
|
44
|
-
const cohesion = calculatePythonCohesion(exports, imports);
|
|
45
|
-
const circularDependencies = detectCircularDependencies(
|
|
46
|
-
file,
|
|
47
|
-
dependencyGraph
|
|
48
|
-
);
|
|
49
|
-
results.push({
|
|
50
|
-
file,
|
|
51
|
-
importDepth,
|
|
52
|
-
contextBudget,
|
|
53
|
-
cohesion,
|
|
54
|
-
imports,
|
|
55
|
-
exports,
|
|
56
|
-
metrics: {
|
|
57
|
-
linesOfCode,
|
|
58
|
-
importCount: imports.length,
|
|
59
|
-
exportCount: exports.length,
|
|
60
|
-
circularDependencies
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
} catch (error) {
|
|
64
|
-
console.warn(`Failed to analyze ${file}:`, error);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
return results;
|
|
68
|
-
}
|
|
69
|
-
async function buildPythonDependencyGraph(files, rootDir) {
|
|
70
|
-
const graph = /* @__PURE__ */ new Map();
|
|
71
|
-
const parser = getParser("dummy.py");
|
|
72
|
-
if (!parser) return graph;
|
|
73
|
-
for (const file of files) {
|
|
74
|
-
try {
|
|
75
|
-
const code = await fs.promises.readFile(file, "utf-8");
|
|
76
|
-
const result = parser.parse(code, file);
|
|
77
|
-
const dependencies = /* @__PURE__ */ new Set();
|
|
78
|
-
for (const imp of result.imports) {
|
|
79
|
-
const resolved = resolvePythonImport(file, imp.source, rootDir);
|
|
80
|
-
if (resolved && files.includes(resolved)) {
|
|
81
|
-
dependencies.add(resolved);
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
graph.set(file, dependencies);
|
|
85
|
-
} catch (error) {
|
|
86
|
-
void error;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return graph;
|
|
90
|
-
}
|
|
91
|
-
function resolvePythonImport(fromFile, importPath, rootDir) {
|
|
92
|
-
const dir = dirname(fromFile);
|
|
93
|
-
if (importPath.startsWith(".")) {
|
|
94
|
-
const parts = importPath.split(".");
|
|
95
|
-
let upCount = 0;
|
|
96
|
-
while (parts[0] === "") {
|
|
97
|
-
upCount++;
|
|
98
|
-
parts.shift();
|
|
99
|
-
}
|
|
100
|
-
let targetDir = dir;
|
|
101
|
-
for (let i = 0; i < upCount - 1; i++) {
|
|
102
|
-
targetDir = dirname(targetDir);
|
|
103
|
-
}
|
|
104
|
-
const modulePath = parts.join("/");
|
|
105
|
-
const possiblePaths = [
|
|
106
|
-
resolve(targetDir, `${modulePath}.py`),
|
|
107
|
-
resolve(targetDir, modulePath, "__init__.py")
|
|
108
|
-
];
|
|
109
|
-
for (const path of possiblePaths) {
|
|
110
|
-
if (fs.existsSync(path)) {
|
|
111
|
-
return path;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
const modulePath = importPath.replace(/\./g, "/");
|
|
116
|
-
const possiblePaths = [
|
|
117
|
-
resolve(rootDir, `${modulePath}.py`),
|
|
118
|
-
resolve(rootDir, modulePath, "__init__.py")
|
|
119
|
-
];
|
|
120
|
-
for (const path of possiblePaths) {
|
|
121
|
-
if (fs.existsSync(path)) {
|
|
122
|
-
return path;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
return void 0;
|
|
127
|
-
}
|
|
128
|
-
async function calculatePythonImportDepth(file, dependencyGraph, visited, depth = 0) {
|
|
129
|
-
if (visited.has(file)) {
|
|
130
|
-
return depth;
|
|
131
|
-
}
|
|
132
|
-
visited.add(file);
|
|
133
|
-
const dependencies = dependencyGraph.get(file) || /* @__PURE__ */ new Set();
|
|
134
|
-
if (dependencies.size === 0) {
|
|
135
|
-
return depth;
|
|
136
|
-
}
|
|
137
|
-
let maxDepth = depth;
|
|
138
|
-
for (const dep of dependencies) {
|
|
139
|
-
const depDepth = await calculatePythonImportDepth(
|
|
140
|
-
dep,
|
|
141
|
-
dependencyGraph,
|
|
142
|
-
new Set(visited),
|
|
143
|
-
depth + 1
|
|
144
|
-
);
|
|
145
|
-
maxDepth = Math.max(maxDepth, depDepth);
|
|
146
|
-
}
|
|
147
|
-
return maxDepth;
|
|
148
|
-
}
|
|
149
|
-
function estimateContextBudget(code, imports, dependencyGraph) {
|
|
150
|
-
void dependencyGraph;
|
|
151
|
-
let budget = estimateTokens(code);
|
|
152
|
-
const avgTokensPerDep = 500;
|
|
153
|
-
budget += imports.length * avgTokensPerDep;
|
|
154
|
-
return budget;
|
|
155
|
-
}
|
|
156
|
-
function calculatePythonCohesion(exports, imports) {
|
|
157
|
-
if (exports.length === 0) return 1;
|
|
158
|
-
const exportCount = exports.length;
|
|
159
|
-
const importCount = imports.length;
|
|
160
|
-
let cohesion = 1;
|
|
161
|
-
if (exportCount > 10) {
|
|
162
|
-
cohesion *= 0.6;
|
|
163
|
-
} else if (exportCount > 5) {
|
|
164
|
-
cohesion *= 0.8;
|
|
165
|
-
}
|
|
166
|
-
if (exportCount > 0) {
|
|
167
|
-
const ratio = importCount / exportCount;
|
|
168
|
-
if (ratio > 2) {
|
|
169
|
-
cohesion *= 1.1;
|
|
170
|
-
} else if (ratio < 0.5) {
|
|
171
|
-
cohesion *= 0.9;
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
return Math.min(1, Math.max(0, cohesion));
|
|
175
|
-
}
|
|
176
|
-
function detectCircularDependencies(file, dependencyGraph) {
|
|
177
|
-
const circular = [];
|
|
178
|
-
const visited = /* @__PURE__ */ new Set();
|
|
179
|
-
const recursionStack = /* @__PURE__ */ new Set();
|
|
180
|
-
function dfs(current, path) {
|
|
181
|
-
if (recursionStack.has(current)) {
|
|
182
|
-
const cycleStart = path.indexOf(current);
|
|
183
|
-
const cycle = path.slice(cycleStart).concat([current]);
|
|
184
|
-
circular.push(cycle.join(" \u2192 "));
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
if (visited.has(current)) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
visited.add(current);
|
|
191
|
-
recursionStack.add(current);
|
|
192
|
-
const dependencies = dependencyGraph.get(current) || /* @__PURE__ */ new Set();
|
|
193
|
-
for (const dep of dependencies) {
|
|
194
|
-
dfs(dep, [...path, current]);
|
|
195
|
-
}
|
|
196
|
-
recursionStack.delete(current);
|
|
197
|
-
}
|
|
198
|
-
dfs(file, []);
|
|
199
|
-
return [...new Set(circular)];
|
|
200
|
-
}
|
|
201
|
-
export {
|
|
202
|
-
analyzePythonContext
|
|
203
|
-
};
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__require
|
|
3
|
-
} from "./chunk-Y6FXYEAI.mjs";
|
|
4
|
-
|
|
5
|
-
// src/analyzers/python-context.ts
|
|
6
|
-
import { getParser, estimateTokens } from "@aiready/core";
|
|
7
|
-
import { resolve, dirname } from "path";
|
|
8
|
-
async function analyzePythonContext(files, rootDir) {
|
|
9
|
-
const results = [];
|
|
10
|
-
const parser = getParser("dummy.py");
|
|
11
|
-
if (!parser) {
|
|
12
|
-
console.warn("Python parser not available");
|
|
13
|
-
return results;
|
|
14
|
-
}
|
|
15
|
-
const pythonFiles = files.filter((f) => f.toLowerCase().endsWith(".py"));
|
|
16
|
-
const dependencyGraph = await buildPythonDependencyGraph(pythonFiles, rootDir);
|
|
17
|
-
for (const file of pythonFiles) {
|
|
18
|
-
try {
|
|
19
|
-
const fs = await import("fs");
|
|
20
|
-
const code = await fs.promises.readFile(file, "utf-8");
|
|
21
|
-
const result = parser.parse(code, file);
|
|
22
|
-
const imports = result.imports.map((imp) => ({
|
|
23
|
-
source: imp.source,
|
|
24
|
-
specifiers: imp.specifiers,
|
|
25
|
-
isRelative: imp.source.startsWith("."),
|
|
26
|
-
resolvedPath: resolvePythonImport(file, imp.source, rootDir)
|
|
27
|
-
}));
|
|
28
|
-
const exports = result.exports.map((exp) => ({
|
|
29
|
-
name: exp.name,
|
|
30
|
-
type: exp.type
|
|
31
|
-
}));
|
|
32
|
-
const linesOfCode = code.split("\n").length;
|
|
33
|
-
const importDepth = await calculatePythonImportDepth(file, dependencyGraph, /* @__PURE__ */ new Set());
|
|
34
|
-
const contextBudget = estimateContextBudget(code, imports, dependencyGraph);
|
|
35
|
-
const cohesion = calculatePythonCohesion(exports, imports);
|
|
36
|
-
const circularDependencies = detectCircularDependencies(file, dependencyGraph);
|
|
37
|
-
results.push({
|
|
38
|
-
file,
|
|
39
|
-
importDepth,
|
|
40
|
-
contextBudget,
|
|
41
|
-
cohesion,
|
|
42
|
-
imports,
|
|
43
|
-
exports,
|
|
44
|
-
metrics: {
|
|
45
|
-
linesOfCode,
|
|
46
|
-
importCount: imports.length,
|
|
47
|
-
exportCount: exports.length,
|
|
48
|
-
circularDependencies
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
} catch (error) {
|
|
52
|
-
console.warn(`Failed to analyze ${file}:`, error);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return results;
|
|
56
|
-
}
|
|
57
|
-
async function buildPythonDependencyGraph(files, rootDir) {
|
|
58
|
-
const graph = /* @__PURE__ */ new Map();
|
|
59
|
-
const parser = getParser("dummy.py");
|
|
60
|
-
if (!parser) return graph;
|
|
61
|
-
for (const file of files) {
|
|
62
|
-
try {
|
|
63
|
-
const fs = await import("fs");
|
|
64
|
-
const code = await fs.promises.readFile(file, "utf-8");
|
|
65
|
-
const result = parser.parse(code, file);
|
|
66
|
-
const dependencies = /* @__PURE__ */ new Set();
|
|
67
|
-
for (const imp of result.imports) {
|
|
68
|
-
const resolved = resolvePythonImport(file, imp.source, rootDir);
|
|
69
|
-
if (resolved && files.includes(resolved)) {
|
|
70
|
-
dependencies.add(resolved);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
graph.set(file, dependencies);
|
|
74
|
-
} catch (error) {
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return graph;
|
|
78
|
-
}
|
|
79
|
-
function resolvePythonImport(fromFile, importPath, rootDir) {
|
|
80
|
-
const dir = dirname(fromFile);
|
|
81
|
-
if (importPath.startsWith(".")) {
|
|
82
|
-
const parts = importPath.split(".");
|
|
83
|
-
let upCount = 0;
|
|
84
|
-
while (parts[0] === "") {
|
|
85
|
-
upCount++;
|
|
86
|
-
parts.shift();
|
|
87
|
-
}
|
|
88
|
-
let targetDir = dir;
|
|
89
|
-
for (let i = 0; i < upCount - 1; i++) {
|
|
90
|
-
targetDir = dirname(targetDir);
|
|
91
|
-
}
|
|
92
|
-
const modulePath = parts.join("/");
|
|
93
|
-
const possiblePaths = [
|
|
94
|
-
resolve(targetDir, `${modulePath}.py`),
|
|
95
|
-
resolve(targetDir, modulePath, "__init__.py")
|
|
96
|
-
];
|
|
97
|
-
const fs = __require("fs");
|
|
98
|
-
for (const path of possiblePaths) {
|
|
99
|
-
if (fs.existsSync(path)) {
|
|
100
|
-
return path;
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
} else {
|
|
104
|
-
const modulePath = importPath.replace(/\./g, "/");
|
|
105
|
-
const possiblePaths = [
|
|
106
|
-
resolve(rootDir, `${modulePath}.py`),
|
|
107
|
-
resolve(rootDir, modulePath, "__init__.py")
|
|
108
|
-
];
|
|
109
|
-
const fs = __require("fs");
|
|
110
|
-
for (const path of possiblePaths) {
|
|
111
|
-
if (fs.existsSync(path)) {
|
|
112
|
-
return path;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
return void 0;
|
|
117
|
-
}
|
|
118
|
-
async function calculatePythonImportDepth(file, dependencyGraph, visited, depth = 0) {
|
|
119
|
-
if (visited.has(file)) {
|
|
120
|
-
return depth;
|
|
121
|
-
}
|
|
122
|
-
visited.add(file);
|
|
123
|
-
const dependencies = dependencyGraph.get(file) || /* @__PURE__ */ new Set();
|
|
124
|
-
if (dependencies.size === 0) {
|
|
125
|
-
return depth;
|
|
126
|
-
}
|
|
127
|
-
let maxDepth = depth;
|
|
128
|
-
for (const dep of dependencies) {
|
|
129
|
-
const depDepth = await calculatePythonImportDepth(
|
|
130
|
-
dep,
|
|
131
|
-
dependencyGraph,
|
|
132
|
-
new Set(visited),
|
|
133
|
-
depth + 1
|
|
134
|
-
);
|
|
135
|
-
maxDepth = Math.max(maxDepth, depDepth);
|
|
136
|
-
}
|
|
137
|
-
return maxDepth;
|
|
138
|
-
}
|
|
139
|
-
function estimateContextBudget(code, imports, dependencyGraph) {
|
|
140
|
-
let budget = estimateTokens(code);
|
|
141
|
-
const avgTokensPerDep = 500;
|
|
142
|
-
budget += imports.length * avgTokensPerDep;
|
|
143
|
-
return budget;
|
|
144
|
-
}
|
|
145
|
-
function calculatePythonCohesion(exports, imports) {
|
|
146
|
-
if (exports.length === 0) return 1;
|
|
147
|
-
const exportCount = exports.length;
|
|
148
|
-
const importCount = imports.length;
|
|
149
|
-
let cohesion = 1;
|
|
150
|
-
if (exportCount > 10) {
|
|
151
|
-
cohesion *= 0.6;
|
|
152
|
-
} else if (exportCount > 5) {
|
|
153
|
-
cohesion *= 0.8;
|
|
154
|
-
}
|
|
155
|
-
if (exportCount > 0) {
|
|
156
|
-
const ratio = importCount / exportCount;
|
|
157
|
-
if (ratio > 2) {
|
|
158
|
-
cohesion *= 1.1;
|
|
159
|
-
} else if (ratio < 0.5) {
|
|
160
|
-
cohesion *= 0.9;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return Math.min(1, Math.max(0, cohesion));
|
|
164
|
-
}
|
|
165
|
-
function detectCircularDependencies(file, dependencyGraph) {
|
|
166
|
-
const circular = [];
|
|
167
|
-
const visited = /* @__PURE__ */ new Set();
|
|
168
|
-
const recursionStack = /* @__PURE__ */ new Set();
|
|
169
|
-
function dfs(current, path) {
|
|
170
|
-
if (recursionStack.has(current)) {
|
|
171
|
-
const cycleStart = path.indexOf(current);
|
|
172
|
-
const cycle = path.slice(cycleStart).concat([current]);
|
|
173
|
-
circular.push(cycle.join(" \u2192 "));
|
|
174
|
-
return;
|
|
175
|
-
}
|
|
176
|
-
if (visited.has(current)) {
|
|
177
|
-
return;
|
|
178
|
-
}
|
|
179
|
-
visited.add(current);
|
|
180
|
-
recursionStack.add(current);
|
|
181
|
-
const dependencies = dependencyGraph.get(current) || /* @__PURE__ */ new Set();
|
|
182
|
-
for (const dep of dependencies) {
|
|
183
|
-
dfs(dep, [...path, current]);
|
|
184
|
-
}
|
|
185
|
-
recursionStack.delete(current);
|
|
186
|
-
}
|
|
187
|
-
dfs(file, []);
|
|
188
|
-
return [...new Set(circular)];
|
|
189
|
-
}
|
|
190
|
-
export {
|
|
191
|
-
analyzePythonContext
|
|
192
|
-
};
|
package/dist/remediation.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { FileClassification } from './types';
|
|
2
|
-
/**
|
|
3
|
-
* Get classification-specific recommendations
|
|
4
|
-
*/
|
|
5
|
-
export declare function getClassificationRecommendations(classification: FileClassification, file: string, issues: string[]): string[];
|
|
6
|
-
/**
|
|
7
|
-
* Generate general context recommendations
|
|
8
|
-
*/
|
|
9
|
-
export declare function getGeneralRecommendations(metrics: {
|
|
10
|
-
contextBudget: number;
|
|
11
|
-
importDepth: number;
|
|
12
|
-
circularDeps: string[][];
|
|
13
|
-
cohesionScore: number;
|
|
14
|
-
fragmentationScore: number;
|
|
15
|
-
}, thresholds: {
|
|
16
|
-
maxContextBudget: number;
|
|
17
|
-
maxDepth: number;
|
|
18
|
-
minCohesion: number;
|
|
19
|
-
maxFragmentation: number;
|
|
20
|
-
}): {
|
|
21
|
-
recommendations: string[];
|
|
22
|
-
issues: string[];
|
|
23
|
-
severity: any;
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=remediation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remediation.d.ts","sourceRoot":"","sources":["../src/remediation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAElD;;GAEG;AACH,wBAAgB,gCAAgC,CAC9C,cAAc,EAAE,kBAAkB,EAClC,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EAAE,GACf,MAAM,EAAE,CAwDV;AAED;;GAEG;AACH,wBAAgB,yBAAyB,CACvC,OAAO,EAAE;IACP,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,EAAE,EAAE,CAAC;IACzB,aAAa,EAAE,MAAM,CAAC;IACtB,kBAAkB,EAAE,MAAM,CAAC;CAC5B,EACD,UAAU,EAAE;IACV,gBAAgB,EAAE,MAAM,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,EAAE,MAAM,CAAC;CAC1B,GACA;IACD,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,QAAQ,EAAE,GAAG,CAAC;CACf,CAkDA"}
|
package/dist/remediation.js
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get classification-specific recommendations
|
|
3
|
-
*/
|
|
4
|
-
export function getClassificationRecommendations(classification, file, issues) {
|
|
5
|
-
switch (classification) {
|
|
6
|
-
case 'barrel-export':
|
|
7
|
-
return [
|
|
8
|
-
'Barrel export file detected - multiple domains are expected here',
|
|
9
|
-
'Consider if this barrel export improves or hinders discoverability',
|
|
10
|
-
];
|
|
11
|
-
case 'type-definition':
|
|
12
|
-
return [
|
|
13
|
-
'Type definition file - centralized types improve consistency',
|
|
14
|
-
'Consider splitting if file becomes too large (>500 lines)',
|
|
15
|
-
];
|
|
16
|
-
case 'cohesive-module':
|
|
17
|
-
return [
|
|
18
|
-
'Module has good cohesion despite its size',
|
|
19
|
-
'Consider documenting the module boundaries for AI assistants',
|
|
20
|
-
];
|
|
21
|
-
case 'utility-module':
|
|
22
|
-
return [
|
|
23
|
-
'Utility module detected - multiple domains are acceptable here',
|
|
24
|
-
'Consider grouping related utilities by prefix or domain for better discoverability',
|
|
25
|
-
];
|
|
26
|
-
case 'service-file':
|
|
27
|
-
return [
|
|
28
|
-
'Service file detected - orchestration of multiple dependencies is expected',
|
|
29
|
-
'Consider documenting service boundaries and dependencies',
|
|
30
|
-
];
|
|
31
|
-
case 'lambda-handler':
|
|
32
|
-
return [
|
|
33
|
-
'Lambda handler detected - coordination of services is expected',
|
|
34
|
-
'Ensure handler has clear single responsibility',
|
|
35
|
-
];
|
|
36
|
-
case 'email-template':
|
|
37
|
-
return [
|
|
38
|
-
'Email template detected - references multiple domains for rendering',
|
|
39
|
-
'Template structure is cohesive by design',
|
|
40
|
-
];
|
|
41
|
-
case 'parser-file':
|
|
42
|
-
return [
|
|
43
|
-
'Parser/transformer file detected - handles multiple data sources',
|
|
44
|
-
'Consider documenting input/output schemas',
|
|
45
|
-
];
|
|
46
|
-
case 'nextjs-page':
|
|
47
|
-
return [
|
|
48
|
-
'Next.js App Router page detected - metadata/JSON-LD/component pattern is cohesive',
|
|
49
|
-
'Multiple exports (metadata, faqJsonLd, default) serve single page purpose',
|
|
50
|
-
];
|
|
51
|
-
case 'mixed-concerns':
|
|
52
|
-
return [
|
|
53
|
-
'Consider splitting this file by domain',
|
|
54
|
-
'Identify independent responsibilities and extract them',
|
|
55
|
-
'Review import dependencies to understand coupling',
|
|
56
|
-
];
|
|
57
|
-
default:
|
|
58
|
-
return issues;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Generate general context recommendations
|
|
63
|
-
*/
|
|
64
|
-
export function getGeneralRecommendations(metrics, thresholds) {
|
|
65
|
-
const recommendations = [];
|
|
66
|
-
const issues = [];
|
|
67
|
-
let severity = 'info';
|
|
68
|
-
if (metrics.contextBudget > thresholds.maxContextBudget) {
|
|
69
|
-
issues.push(`High context budget: ${Math.round(metrics.contextBudget / 1000)}k tokens`);
|
|
70
|
-
recommendations.push('Reduce dependencies or split the file to lower context window requirements');
|
|
71
|
-
severity = 'major';
|
|
72
|
-
}
|
|
73
|
-
if (metrics.importDepth > thresholds.maxDepth) {
|
|
74
|
-
issues.push(`Deep import chain: ${metrics.importDepth} levels`);
|
|
75
|
-
recommendations.push('Flatten the dependency graph by reducing nesting');
|
|
76
|
-
if (severity !== 'critical')
|
|
77
|
-
severity = 'major';
|
|
78
|
-
}
|
|
79
|
-
if (metrics.circularDeps.length > 0) {
|
|
80
|
-
issues.push(`Circular dependencies detected: ${metrics.circularDeps.length}`);
|
|
81
|
-
recommendations.push('Refactor to remove circular imports (use dependency injection or interfaces)');
|
|
82
|
-
severity = 'critical';
|
|
83
|
-
}
|
|
84
|
-
if (metrics.cohesionScore < thresholds.minCohesion) {
|
|
85
|
-
issues.push(`Low cohesion score: ${metrics.cohesionScore.toFixed(2)}`);
|
|
86
|
-
recommendations.push('Extract unrelated exports into separate domain-specific modules');
|
|
87
|
-
if (severity === 'info')
|
|
88
|
-
severity = 'minor';
|
|
89
|
-
}
|
|
90
|
-
if (metrics.fragmentationScore > thresholds.maxFragmentation) {
|
|
91
|
-
issues.push(`High domain fragmentation: ${metrics.fragmentationScore.toFixed(2)}`);
|
|
92
|
-
recommendations.push('Consolidate domain-related files into fewer directories');
|
|
93
|
-
if (severity === 'info')
|
|
94
|
-
severity = 'minor';
|
|
95
|
-
}
|
|
96
|
-
return { recommendations, issues, severity: severity };
|
|
97
|
-
}
|
|
98
|
-
//# sourceMappingURL=remediation.js.map
|
package/dist/remediation.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"remediation.js","sourceRoot":"","sources":["../src/remediation.ts"],"names":[],"mappings":"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"}
|
package/dist/scoring.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type CostConfig } from '@aiready/core';
|
|
2
|
-
import type { ToolScoringOutput } from '@aiready/core';
|
|
3
|
-
import type { ContextSummary } from './types';
|
|
4
|
-
/**
|
|
5
|
-
* Calculate AI Readiness Score for context efficiency (0-100)
|
|
6
|
-
*/
|
|
7
|
-
export declare function calculateContextScore(summary: ContextSummary, costConfig?: Partial<CostConfig>): ToolScoringOutput;
|
|
8
|
-
export declare function mapScoreToRating(score: number): string;
|
|
9
|
-
//# sourceMappingURL=scoring.d.ts.map
|
package/dist/scoring.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"scoring.d.ts","sourceRoot":"","sources":["../src/scoring.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,UAAU,EAEhB,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,cAAc,EACvB,UAAU,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,GAC/B,iBAAiB,CA6KnB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAMtD"}
|
package/dist/scoring.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
import { calculateMonthlyCost, calculateProductivityImpact, DEFAULT_COST_CONFIG, ToolName, } from '@aiready/core';
|
|
2
|
-
/**
|
|
3
|
-
* Calculate AI Readiness Score for context efficiency (0-100)
|
|
4
|
-
*/
|
|
5
|
-
export function calculateContextScore(summary, costConfig) {
|
|
6
|
-
const { avgContextBudget, maxContextBudget, avgImportDepth, maxImportDepth, avgFragmentation, criticalIssues, majorIssues, totalFiles, } = summary;
|
|
7
|
-
// More reasonable thresholds for modern codebases
|
|
8
|
-
const budgetScore = avgContextBudget < 8000
|
|
9
|
-
? 100
|
|
10
|
-
: Math.max(0, 100 - (avgContextBudget - 8000) / 200);
|
|
11
|
-
const depthScore = avgImportDepth < 8 ? 100 : Math.max(0, 100 - (avgImportDepth - 8) * 5);
|
|
12
|
-
const fragmentationScore = avgFragmentation < 0.5
|
|
13
|
-
? 100
|
|
14
|
-
: Math.max(0, 100 - (avgFragmentation - 0.5) * 100);
|
|
15
|
-
// Cap penalties to prevent score going to 0
|
|
16
|
-
const criticalPenalty = Math.min(20, criticalIssues * 3); // Max 20 points
|
|
17
|
-
const majorPenalty = Math.min(15, majorIssues * 1); // Max 15 points
|
|
18
|
-
const maxBudgetPenalty = maxContextBudget > 15000
|
|
19
|
-
? Math.min(20, (maxContextBudget - 15000) / 500)
|
|
20
|
-
: 0;
|
|
21
|
-
// Add bonus for well-organized codebases
|
|
22
|
-
let bonus = 0;
|
|
23
|
-
if (criticalIssues === 0 && majorIssues === 0 && avgFragmentation < 0.2) {
|
|
24
|
-
bonus = 5; // Well-organized codebase bonus
|
|
25
|
-
}
|
|
26
|
-
const rawScore = budgetScore * 0.35 + depthScore * 0.25 + fragmentationScore * 0.25 + bonus;
|
|
27
|
-
const finalScore = rawScore - Math.min(30, criticalPenalty + majorPenalty) - maxBudgetPenalty;
|
|
28
|
-
const score = Math.max(0, Math.min(100, Math.round(finalScore)));
|
|
29
|
-
const factors = [
|
|
30
|
-
{
|
|
31
|
-
name: 'Context Budget',
|
|
32
|
-
impact: Math.round(budgetScore * 0.35 - 35),
|
|
33
|
-
description: `Avg ${Math.round(avgContextBudget)} tokens per file ${avgContextBudget < 8000 ? '(excellent)' : avgContextBudget < 12000 ? '(acceptable)' : '(high)'}`,
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
name: 'Import Depth',
|
|
37
|
-
impact: Math.round(depthScore * 0.25 - 25),
|
|
38
|
-
description: `Avg ${avgImportDepth.toFixed(1)} levels ${avgImportDepth < 8 ? '(excellent)' : avgImportDepth < 12 ? '(acceptable)' : '(deep)'}`,
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
name: 'Fragmentation',
|
|
42
|
-
impact: Math.round(fragmentationScore * 0.25 - 25),
|
|
43
|
-
description: `${(avgFragmentation * 100).toFixed(0)}% fragmentation ${avgFragmentation < 0.3 ? '(well-organized)' : avgFragmentation < 0.5 ? '(moderate)' : '(high)'}`,
|
|
44
|
-
},
|
|
45
|
-
];
|
|
46
|
-
if (bonus > 0) {
|
|
47
|
-
factors.push({
|
|
48
|
-
name: 'Well-Organized Codebase',
|
|
49
|
-
impact: bonus,
|
|
50
|
-
description: 'No critical/major issues and low fragmentation',
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
if (criticalIssues > 0) {
|
|
54
|
-
factors.push({
|
|
55
|
-
name: 'Critical Issues',
|
|
56
|
-
impact: -criticalPenalty,
|
|
57
|
-
description: `${criticalIssues} critical context issue${criticalIssues > 1 ? 's' : ''}`,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
if (majorIssues > 0) {
|
|
61
|
-
factors.push({
|
|
62
|
-
name: 'Major Issues',
|
|
63
|
-
impact: -majorPenalty,
|
|
64
|
-
description: `${majorIssues} major context issue${majorIssues > 1 ? 's' : ''}`,
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
if (maxBudgetPenalty > 0) {
|
|
68
|
-
factors.push({
|
|
69
|
-
name: 'Extreme File Detected',
|
|
70
|
-
impact: -Math.round(maxBudgetPenalty),
|
|
71
|
-
description: `One file requires ${Math.round(maxContextBudget)} tokens (very high)`,
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
const recommendations = [];
|
|
75
|
-
if (avgContextBudget > 12000) {
|
|
76
|
-
const estimatedImpact = Math.min(15, Math.round((avgContextBudget - 12000) / 1000));
|
|
77
|
-
recommendations.push({
|
|
78
|
-
action: 'Reduce file dependencies to lower context requirements',
|
|
79
|
-
estimatedImpact,
|
|
80
|
-
priority: 'high',
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
if (avgImportDepth > 10) {
|
|
84
|
-
const estimatedImpact = Math.min(10, Math.round((avgImportDepth - 10) * 1.5));
|
|
85
|
-
recommendations.push({
|
|
86
|
-
action: 'Flatten import chains to reduce depth',
|
|
87
|
-
estimatedImpact,
|
|
88
|
-
priority: avgImportDepth > 15 ? 'high' : 'medium',
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
if (avgFragmentation > 0.5) {
|
|
92
|
-
const estimatedImpact = Math.min(12, Math.round((avgFragmentation - 0.5) * 40));
|
|
93
|
-
recommendations.push({
|
|
94
|
-
action: 'Consolidate related code into cohesive modules',
|
|
95
|
-
estimatedImpact,
|
|
96
|
-
priority: 'medium',
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
if (maxContextBudget > 20000) {
|
|
100
|
-
recommendations.push({
|
|
101
|
-
action: `Split large file (${Math.round(maxContextBudget)} tokens) into smaller modules`,
|
|
102
|
-
estimatedImpact: 8,
|
|
103
|
-
priority: 'high',
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
const cfg = { ...DEFAULT_COST_CONFIG, ...costConfig };
|
|
107
|
-
const estimatedMonthlyCost = calculateMonthlyCost(avgContextBudget * (totalFiles || 1), cfg);
|
|
108
|
-
const issues = [
|
|
109
|
-
...Array(criticalIssues).fill({ severity: 'critical' }),
|
|
110
|
-
...Array(majorIssues).fill({ severity: 'major' }),
|
|
111
|
-
];
|
|
112
|
-
const productivityImpact = calculateProductivityImpact(issues);
|
|
113
|
-
return {
|
|
114
|
-
toolName: ToolName.ContextAnalyzer,
|
|
115
|
-
score,
|
|
116
|
-
rawMetrics: {
|
|
117
|
-
avgContextBudget: Math.round(avgContextBudget),
|
|
118
|
-
maxContextBudget: Math.round(maxContextBudget),
|
|
119
|
-
avgImportDepth: Math.round(avgImportDepth * 10) / 10,
|
|
120
|
-
maxImportDepth,
|
|
121
|
-
avgFragmentation: Math.round(avgFragmentation * 100) / 100,
|
|
122
|
-
criticalIssues,
|
|
123
|
-
majorIssues,
|
|
124
|
-
estimatedMonthlyCost,
|
|
125
|
-
estimatedDeveloperHours: productivityImpact.totalHours,
|
|
126
|
-
},
|
|
127
|
-
factors,
|
|
128
|
-
recommendations,
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
export function mapScoreToRating(score) {
|
|
132
|
-
if (score >= 90)
|
|
133
|
-
return 'excellent';
|
|
134
|
-
if (score >= 75)
|
|
135
|
-
return 'good';
|
|
136
|
-
if (score >= 60)
|
|
137
|
-
return 'fair';
|
|
138
|
-
if (score >= 40)
|
|
139
|
-
return 'needs work';
|
|
140
|
-
return 'critical';
|
|
141
|
-
}
|
|
142
|
-
//# sourceMappingURL=scoring.js.map
|