@aiready/change-amplification 0.14.9 → 0.14.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 +23 -24
- package/dist/index.d.mts +3 -8
- package/dist/index.d.ts +3 -8
- package/dist/index.js +7 -32
- package/dist/index.mjs +4 -31
- package/package.json +2 -2
- package/src/__tests__/provider.test.ts +6 -36
- package/src/index.ts +5 -11
- package/src/provider.ts +1 -1
- package/dist/chunk-2EOPHC5S.mjs +0 -112
- package/dist/chunk-3CM4X7K3.mjs +0 -111
- package/dist/chunk-7GH73LRM.mjs +0 -128
- package/dist/chunk-A5ACPWWO.mjs +0 -114
- package/dist/chunk-DS7GBUP2.mjs +0 -100
- package/dist/chunk-GLHIV53G.mjs +0 -120
- package/dist/chunk-MARO4FT6.mjs +0 -112
- package/dist/chunk-OBBL7HKE.mjs +0 -146
- package/dist/chunk-SHJMNP6Q.mjs +0 -126
- package/dist/chunk-V5J3BP4N.mjs +0 -117
- package/dist/chunk-VW57ZQRN.mjs +0 -103
- package/dist/chunk-XCXQGNCX.mjs +0 -129
package/dist/chunk-A5ACPWWO.mjs
DELETED
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
// src/analyzer.ts
|
|
9
|
-
import * as fs from "fs";
|
|
10
|
-
import * as path from "path";
|
|
11
|
-
import { globSync } from "glob";
|
|
12
|
-
import { calculateChangeAmplification } from "@aiready/core";
|
|
13
|
-
import { getParser } from "@aiready/core";
|
|
14
|
-
function collectFiles(dir, options) {
|
|
15
|
-
const includePatterns = options.include && options.include.length > 0 ? options.include : ["**/*.{ts,tsx,js,jsx,py,go}"];
|
|
16
|
-
const excludePatterns = options.exclude && options.exclude.length > 0 ? options.exclude : ["**/node_modules/**", "**/dist/**", "**/.git/**"];
|
|
17
|
-
let matchedFiles = [];
|
|
18
|
-
for (const pattern of includePatterns) {
|
|
19
|
-
const files = globSync(pattern, {
|
|
20
|
-
cwd: dir,
|
|
21
|
-
ignore: excludePatterns,
|
|
22
|
-
absolute: true
|
|
23
|
-
});
|
|
24
|
-
matchedFiles = matchedFiles.concat(files);
|
|
25
|
-
}
|
|
26
|
-
return [...new Set(matchedFiles)];
|
|
27
|
-
}
|
|
28
|
-
async function analyzeChangeAmplification(options) {
|
|
29
|
-
const rootDir = path.resolve(options.rootDir || ".");
|
|
30
|
-
const files = collectFiles(rootDir, options);
|
|
31
|
-
const dependencyGraph = /* @__PURE__ */ new Map();
|
|
32
|
-
const reverseGraph = /* @__PURE__ */ new Map();
|
|
33
|
-
for (const file of files) {
|
|
34
|
-
dependencyGraph.set(file, []);
|
|
35
|
-
reverseGraph.set(file, []);
|
|
36
|
-
}
|
|
37
|
-
for (const file of files) {
|
|
38
|
-
try {
|
|
39
|
-
const parser = getParser(file);
|
|
40
|
-
if (!parser) continue;
|
|
41
|
-
const content = fs.readFileSync(file, "utf8");
|
|
42
|
-
const parseResult = parser.parse(content, file);
|
|
43
|
-
const dependencies = parseResult.imports.map((i) => i.source);
|
|
44
|
-
for (const dep of dependencies) {
|
|
45
|
-
const depDir = path.dirname(file);
|
|
46
|
-
const resolvedPath = files.find((f) => {
|
|
47
|
-
if (dep.startsWith(".")) {
|
|
48
|
-
return f.startsWith(path.resolve(depDir, dep));
|
|
49
|
-
} else {
|
|
50
|
-
return f.includes(dep);
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
if (resolvedPath) {
|
|
54
|
-
dependencyGraph.get(file)?.push(resolvedPath);
|
|
55
|
-
reverseGraph.get(resolvedPath)?.push(file);
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
} catch (err) {
|
|
59
|
-
void err;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
const fileMetrics = files.map((file) => {
|
|
63
|
-
const fanOut = dependencyGraph.get(file)?.length || 0;
|
|
64
|
-
const fanIn = reverseGraph.get(file)?.length || 0;
|
|
65
|
-
return { file, fanOut, fanIn };
|
|
66
|
-
});
|
|
67
|
-
const riskResult = calculateChangeAmplification({ files: fileMetrics });
|
|
68
|
-
const results = [];
|
|
69
|
-
for (const hotspot of riskResult.hotspots) {
|
|
70
|
-
const issues = [];
|
|
71
|
-
if (hotspot.amplificationFactor > 20) {
|
|
72
|
-
issues.push({
|
|
73
|
-
type: "change-amplification",
|
|
74
|
-
severity: hotspot.amplificationFactor > 40 ? "critical" : "major",
|
|
75
|
-
message: `High change amplification detected (Factor: ${hotspot.amplificationFactor}). Changes here cascade heavily.`,
|
|
76
|
-
location: { file: hotspot.file, line: 1 },
|
|
77
|
-
suggestion: `Reduce coupling. Fan-out is ${hotspot.fanOut}, Fan-in is ${hotspot.fanIn}.`
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
if (hotspot.amplificationFactor > 5) {
|
|
81
|
-
results.push({
|
|
82
|
-
fileName: hotspot.file,
|
|
83
|
-
issues,
|
|
84
|
-
metrics: {
|
|
85
|
-
aiSignalClarityScore: 100 - hotspot.amplificationFactor
|
|
86
|
-
// Just a rough score
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
return {
|
|
92
|
-
summary: {
|
|
93
|
-
totalFiles: files.length,
|
|
94
|
-
totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
|
|
95
|
-
criticalIssues: results.reduce(
|
|
96
|
-
(sum, r) => sum + r.issues.filter((i) => i.severity === "critical").length,
|
|
97
|
-
0
|
|
98
|
-
),
|
|
99
|
-
majorIssues: results.reduce(
|
|
100
|
-
(sum, r) => sum + r.issues.filter((i) => i.severity === "major").length,
|
|
101
|
-
0
|
|
102
|
-
),
|
|
103
|
-
score: riskResult.score,
|
|
104
|
-
rating: riskResult.rating,
|
|
105
|
-
recommendations: riskResult.recommendations
|
|
106
|
-
},
|
|
107
|
-
results
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export {
|
|
112
|
-
__require,
|
|
113
|
-
analyzeChangeAmplification
|
|
114
|
-
};
|
package/dist/chunk-DS7GBUP2.mjs
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
// src/analyzer.ts
|
|
9
|
-
import * as fs from "fs";
|
|
10
|
-
import * as path from "path";
|
|
11
|
-
import { globSync } from "glob";
|
|
12
|
-
import { calculateChangeAmplification } from "@aiready/core";
|
|
13
|
-
import { parseDependencies } from "@aiready/core";
|
|
14
|
-
function collectFiles(dir, options) {
|
|
15
|
-
const includePatterns = options.include && options.include.length > 0 ? options.include : ["**/*.{ts,tsx,js,jsx,py,go}"];
|
|
16
|
-
const excludePatterns = options.exclude && options.exclude.length > 0 ? options.exclude : ["**/node_modules/**", "**/dist/**", "**/.git/**"];
|
|
17
|
-
let matchedFiles = [];
|
|
18
|
-
for (const pattern of includePatterns) {
|
|
19
|
-
const files = globSync(pattern, { cwd: dir, ignore: excludePatterns, absolute: true });
|
|
20
|
-
matchedFiles = matchedFiles.concat(files);
|
|
21
|
-
}
|
|
22
|
-
return [...new Set(matchedFiles)];
|
|
23
|
-
}
|
|
24
|
-
async function analyzeChangeAmplification(options) {
|
|
25
|
-
const rootDir = path.resolve(options.rootDir || ".");
|
|
26
|
-
const files = collectFiles(rootDir, options);
|
|
27
|
-
const dependencyGraph = /* @__PURE__ */ new Map();
|
|
28
|
-
const reverseGraph = /* @__PURE__ */ new Map();
|
|
29
|
-
for (const file of files) {
|
|
30
|
-
dependencyGraph.set(file, []);
|
|
31
|
-
reverseGraph.set(file, []);
|
|
32
|
-
}
|
|
33
|
-
for (const file of files) {
|
|
34
|
-
try {
|
|
35
|
-
const content = fs.readFileSync(file, "utf8");
|
|
36
|
-
const dependencies = parseDependencies(content);
|
|
37
|
-
for (const dep of dependencies) {
|
|
38
|
-
const depDir = path.dirname(file);
|
|
39
|
-
const resolvedPath = files.find((f) => {
|
|
40
|
-
if (dep.startsWith(".")) {
|
|
41
|
-
return f.startsWith(path.resolve(depDir, dep));
|
|
42
|
-
} else {
|
|
43
|
-
return f.includes(dep);
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
if (resolvedPath) {
|
|
47
|
-
dependencyGraph.get(file)?.push(resolvedPath);
|
|
48
|
-
reverseGraph.get(resolvedPath)?.push(file);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
} catch (err) {
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
const fileMetrics = files.map((file) => {
|
|
55
|
-
const fanOut = dependencyGraph.get(file)?.length || 0;
|
|
56
|
-
const fanIn = reverseGraph.get(file)?.length || 0;
|
|
57
|
-
return { file, fanOut, fanIn };
|
|
58
|
-
});
|
|
59
|
-
const riskResult = calculateChangeAmplification({ files: fileMetrics });
|
|
60
|
-
const results = [];
|
|
61
|
-
for (const hotspot of riskResult.hotspots) {
|
|
62
|
-
const issues = [];
|
|
63
|
-
if (hotspot.amplificationFactor > 20) {
|
|
64
|
-
issues.push({
|
|
65
|
-
type: "change-amplification",
|
|
66
|
-
severity: hotspot.amplificationFactor > 40 ? "critical" : "major",
|
|
67
|
-
message: `High change amplification detected (Factor: ${hotspot.amplificationFactor}). Changes here cascade heavily.`,
|
|
68
|
-
location: { file: hotspot.file, line: 1 },
|
|
69
|
-
suggestion: `Reduce coupling. Fan-out is ${hotspot.fanOut}, Fan-in is ${hotspot.fanIn}.`
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
if (hotspot.amplificationFactor > 5) {
|
|
73
|
-
results.push({
|
|
74
|
-
fileName: hotspot.file,
|
|
75
|
-
issues,
|
|
76
|
-
metrics: {
|
|
77
|
-
aiSignalClarityScore: 100 - hotspot.amplificationFactor
|
|
78
|
-
// Just a rough score
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
summary: {
|
|
85
|
-
totalFiles: files.length,
|
|
86
|
-
totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
|
|
87
|
-
criticalIssues: results.reduce((sum, r) => sum + r.issues.filter((i) => i.severity === "critical").length, 0),
|
|
88
|
-
majorIssues: results.reduce((sum, r) => sum + r.issues.filter((i) => i.severity === "major").length, 0),
|
|
89
|
-
score: riskResult.score,
|
|
90
|
-
rating: riskResult.rating,
|
|
91
|
-
recommendations: riskResult.recommendations
|
|
92
|
-
},
|
|
93
|
-
results
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export {
|
|
98
|
-
__require,
|
|
99
|
-
analyzeChangeAmplification
|
|
100
|
-
};
|
package/dist/chunk-GLHIV53G.mjs
DELETED
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
// src/analyzer.ts
|
|
9
|
-
import * as fs from "fs";
|
|
10
|
-
import * as path from "path";
|
|
11
|
-
import {
|
|
12
|
-
scanFiles,
|
|
13
|
-
calculateChangeAmplification,
|
|
14
|
-
getParser,
|
|
15
|
-
Severity,
|
|
16
|
-
IssueType
|
|
17
|
-
} from "@aiready/core";
|
|
18
|
-
async function analyzeChangeAmplification(options) {
|
|
19
|
-
const files = await scanFiles({
|
|
20
|
-
...options,
|
|
21
|
-
include: options.include || ["**/*.{ts,tsx,js,jsx,py,go}"]
|
|
22
|
-
});
|
|
23
|
-
const dependencyGraph = /* @__PURE__ */ new Map();
|
|
24
|
-
const reverseGraph = /* @__PURE__ */ new Map();
|
|
25
|
-
for (const file of files) {
|
|
26
|
-
dependencyGraph.set(file, []);
|
|
27
|
-
reverseGraph.set(file, []);
|
|
28
|
-
}
|
|
29
|
-
let processed = 0;
|
|
30
|
-
for (const file of files) {
|
|
31
|
-
processed++;
|
|
32
|
-
options.onProgress?.(
|
|
33
|
-
processed,
|
|
34
|
-
files.length,
|
|
35
|
-
`change-amplification: analyzing files`
|
|
36
|
-
);
|
|
37
|
-
try {
|
|
38
|
-
const parser = getParser(file);
|
|
39
|
-
if (!parser) continue;
|
|
40
|
-
const content = fs.readFileSync(file, "utf8");
|
|
41
|
-
const parseResult = parser.parse(content, file);
|
|
42
|
-
const dependencies = parseResult.imports.map((i) => i.source);
|
|
43
|
-
for (const dep of dependencies) {
|
|
44
|
-
const depDir = path.dirname(file);
|
|
45
|
-
const resolvedPath = files.find((f) => {
|
|
46
|
-
if (dep.startsWith(".")) {
|
|
47
|
-
return f.startsWith(path.resolve(depDir, dep));
|
|
48
|
-
} else {
|
|
49
|
-
return f.includes(dep);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
if (resolvedPath) {
|
|
53
|
-
dependencyGraph.get(file)?.push(resolvedPath);
|
|
54
|
-
reverseGraph.get(resolvedPath)?.push(file);
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
} catch (err) {
|
|
58
|
-
void err;
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
const fileMetrics = files.map((file) => {
|
|
62
|
-
const fanOut = dependencyGraph.get(file)?.length || 0;
|
|
63
|
-
const fanIn = reverseGraph.get(file)?.length || 0;
|
|
64
|
-
return { file, fanOut, fanIn };
|
|
65
|
-
});
|
|
66
|
-
const riskResult = calculateChangeAmplification({ files: fileMetrics });
|
|
67
|
-
const results = [];
|
|
68
|
-
const getLevel = (s) => {
|
|
69
|
-
if (s === Severity.Critical || s === "critical") return 4;
|
|
70
|
-
if (s === Severity.Major || s === "major") return 3;
|
|
71
|
-
if (s === Severity.Minor || s === "minor") return 2;
|
|
72
|
-
if (s === Severity.Info || s === "info") return 1;
|
|
73
|
-
return 0;
|
|
74
|
-
};
|
|
75
|
-
for (const hotspot of riskResult.hotspots) {
|
|
76
|
-
const issues = [];
|
|
77
|
-
if (hotspot.amplificationFactor > 20) {
|
|
78
|
-
issues.push({
|
|
79
|
-
type: IssueType.ChangeAmplification,
|
|
80
|
-
severity: hotspot.amplificationFactor > 40 ? Severity.Critical : Severity.Major,
|
|
81
|
-
message: `High change amplification detected (Factor: ${hotspot.amplificationFactor}). Changes here cascade heavily.`,
|
|
82
|
-
location: { file: hotspot.file, line: 1 },
|
|
83
|
-
suggestion: `Reduce coupling. Fan-out is ${hotspot.fanOut}, Fan-in is ${hotspot.fanIn}.`
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
if (hotspot.amplificationFactor > 5) {
|
|
87
|
-
results.push({
|
|
88
|
-
fileName: hotspot.file,
|
|
89
|
-
issues,
|
|
90
|
-
metrics: {
|
|
91
|
-
aiSignalClarityScore: 100 - hotspot.amplificationFactor
|
|
92
|
-
// Just a rough score
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return {
|
|
98
|
-
summary: {
|
|
99
|
-
totalFiles: files.length,
|
|
100
|
-
totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
|
|
101
|
-
criticalIssues: results.reduce(
|
|
102
|
-
(sum, r) => sum + r.issues.filter((i) => getLevel(i.severity) === 4).length,
|
|
103
|
-
0
|
|
104
|
-
),
|
|
105
|
-
majorIssues: results.reduce(
|
|
106
|
-
(sum, r) => sum + r.issues.filter((i) => getLevel(i.severity) === 3).length,
|
|
107
|
-
0
|
|
108
|
-
),
|
|
109
|
-
score: riskResult.score,
|
|
110
|
-
rating: riskResult.rating,
|
|
111
|
-
recommendations: riskResult.recommendations
|
|
112
|
-
},
|
|
113
|
-
results
|
|
114
|
-
};
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
export {
|
|
118
|
-
__require,
|
|
119
|
-
analyzeChangeAmplification
|
|
120
|
-
};
|
package/dist/chunk-MARO4FT6.mjs
DELETED
|
@@ -1,112 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
// src/analyzer.ts
|
|
9
|
-
import * as fs from "fs";
|
|
10
|
-
import * as path from "path";
|
|
11
|
-
import {
|
|
12
|
-
scanFiles,
|
|
13
|
-
calculateChangeAmplification,
|
|
14
|
-
getParser
|
|
15
|
-
} from "@aiready/core";
|
|
16
|
-
async function analyzeChangeAmplification(options) {
|
|
17
|
-
const rootDir = path.resolve(options.rootDir || ".");
|
|
18
|
-
const files = await scanFiles({
|
|
19
|
-
...options,
|
|
20
|
-
include: options.include || ["**/*.{ts,tsx,js,jsx,py,go}"]
|
|
21
|
-
});
|
|
22
|
-
const dependencyGraph = /* @__PURE__ */ new Map();
|
|
23
|
-
const reverseGraph = /* @__PURE__ */ new Map();
|
|
24
|
-
for (const file of files) {
|
|
25
|
-
dependencyGraph.set(file, []);
|
|
26
|
-
reverseGraph.set(file, []);
|
|
27
|
-
}
|
|
28
|
-
let processed = 0;
|
|
29
|
-
for (const file of files) {
|
|
30
|
-
processed++;
|
|
31
|
-
options.onProgress?.(
|
|
32
|
-
processed,
|
|
33
|
-
files.length,
|
|
34
|
-
`change-amplification: analyzing files`
|
|
35
|
-
);
|
|
36
|
-
try {
|
|
37
|
-
const parser = getParser(file);
|
|
38
|
-
if (!parser) continue;
|
|
39
|
-
const content = fs.readFileSync(file, "utf8");
|
|
40
|
-
const parseResult = parser.parse(content, file);
|
|
41
|
-
const dependencies = parseResult.imports.map((i) => i.source);
|
|
42
|
-
for (const dep of dependencies) {
|
|
43
|
-
const depDir = path.dirname(file);
|
|
44
|
-
const resolvedPath = files.find((f) => {
|
|
45
|
-
if (dep.startsWith(".")) {
|
|
46
|
-
return f.startsWith(path.resolve(depDir, dep));
|
|
47
|
-
} else {
|
|
48
|
-
return f.includes(dep);
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
if (resolvedPath) {
|
|
52
|
-
dependencyGraph.get(file)?.push(resolvedPath);
|
|
53
|
-
reverseGraph.get(resolvedPath)?.push(file);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
} catch (err) {
|
|
57
|
-
void err;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
const fileMetrics = files.map((file) => {
|
|
61
|
-
const fanOut = dependencyGraph.get(file)?.length || 0;
|
|
62
|
-
const fanIn = reverseGraph.get(file)?.length || 0;
|
|
63
|
-
return { file, fanOut, fanIn };
|
|
64
|
-
});
|
|
65
|
-
const riskResult = calculateChangeAmplification({ files: fileMetrics });
|
|
66
|
-
const results = [];
|
|
67
|
-
for (const hotspot of riskResult.hotspots) {
|
|
68
|
-
const issues = [];
|
|
69
|
-
if (hotspot.amplificationFactor > 20) {
|
|
70
|
-
issues.push({
|
|
71
|
-
type: "change-amplification",
|
|
72
|
-
severity: hotspot.amplificationFactor > 40 ? "critical" : "major",
|
|
73
|
-
message: `High change amplification detected (Factor: ${hotspot.amplificationFactor}). Changes here cascade heavily.`,
|
|
74
|
-
location: { file: hotspot.file, line: 1 },
|
|
75
|
-
suggestion: `Reduce coupling. Fan-out is ${hotspot.fanOut}, Fan-in is ${hotspot.fanIn}.`
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
if (hotspot.amplificationFactor > 5) {
|
|
79
|
-
results.push({
|
|
80
|
-
fileName: hotspot.file,
|
|
81
|
-
issues,
|
|
82
|
-
metrics: {
|
|
83
|
-
aiSignalClarityScore: 100 - hotspot.amplificationFactor
|
|
84
|
-
// Just a rough score
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return {
|
|
90
|
-
summary: {
|
|
91
|
-
totalFiles: files.length,
|
|
92
|
-
totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
|
|
93
|
-
criticalIssues: results.reduce(
|
|
94
|
-
(sum, r) => sum + r.issues.filter((i) => i.severity === "critical").length,
|
|
95
|
-
0
|
|
96
|
-
),
|
|
97
|
-
majorIssues: results.reduce(
|
|
98
|
-
(sum, r) => sum + r.issues.filter((i) => i.severity === "major").length,
|
|
99
|
-
0
|
|
100
|
-
),
|
|
101
|
-
score: riskResult.score,
|
|
102
|
-
rating: riskResult.rating,
|
|
103
|
-
recommendations: riskResult.recommendations
|
|
104
|
-
},
|
|
105
|
-
results
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export {
|
|
110
|
-
__require,
|
|
111
|
-
analyzeChangeAmplification
|
|
112
|
-
};
|
package/dist/chunk-OBBL7HKE.mjs
DELETED
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
-
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
-
}) : x)(function(x) {
|
|
4
|
-
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
-
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
-
});
|
|
7
|
-
|
|
8
|
-
// src/analyzer.ts
|
|
9
|
-
import * as fs from "fs";
|
|
10
|
-
import * as path from "path";
|
|
11
|
-
import {
|
|
12
|
-
scanFiles,
|
|
13
|
-
calculateChangeAmplification,
|
|
14
|
-
getParser,
|
|
15
|
-
Severity,
|
|
16
|
-
IssueType
|
|
17
|
-
} from "@aiready/core";
|
|
18
|
-
async function analyzeChangeAmplification(options) {
|
|
19
|
-
const files = await scanFiles({
|
|
20
|
-
...options,
|
|
21
|
-
include: options.include || ["**/*.{ts,tsx,js,jsx,py,go}"]
|
|
22
|
-
});
|
|
23
|
-
const dependencyGraph = /* @__PURE__ */ new Map();
|
|
24
|
-
const reverseGraph = /* @__PURE__ */ new Map();
|
|
25
|
-
for (const file of files) {
|
|
26
|
-
dependencyGraph.set(file, []);
|
|
27
|
-
reverseGraph.set(file, []);
|
|
28
|
-
}
|
|
29
|
-
let processed = 0;
|
|
30
|
-
for (const file of files) {
|
|
31
|
-
processed++;
|
|
32
|
-
if (processed % 50 === 0 || processed === files.length) {
|
|
33
|
-
options.onProgress?.(
|
|
34
|
-
processed,
|
|
35
|
-
files.length,
|
|
36
|
-
`analyzing dependencies (${processed}/${files.length})`
|
|
37
|
-
);
|
|
38
|
-
}
|
|
39
|
-
try {
|
|
40
|
-
const parser = getParser(file);
|
|
41
|
-
if (!parser) continue;
|
|
42
|
-
const content = fs.readFileSync(file, "utf8");
|
|
43
|
-
const parseResult = parser.parse(content, file);
|
|
44
|
-
const dependencies = parseResult.imports.map((i) => i.source);
|
|
45
|
-
const extensions = [".ts", ".tsx", ".js", ".jsx"];
|
|
46
|
-
for (const dep of dependencies) {
|
|
47
|
-
const depDir = path.dirname(file);
|
|
48
|
-
let resolvedPath;
|
|
49
|
-
if (dep.startsWith(".")) {
|
|
50
|
-
const absoluteDepBase = path.resolve(depDir, dep);
|
|
51
|
-
for (const ext of extensions) {
|
|
52
|
-
const withExt = absoluteDepBase + ext;
|
|
53
|
-
if (files.includes(withExt)) {
|
|
54
|
-
resolvedPath = withExt;
|
|
55
|
-
break;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
if (!resolvedPath) {
|
|
59
|
-
for (const ext of extensions) {
|
|
60
|
-
const withIndex = path.join(absoluteDepBase, `index${ext}`);
|
|
61
|
-
if (files.includes(withIndex)) {
|
|
62
|
-
resolvedPath = withIndex;
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
} else {
|
|
68
|
-
const depWithoutExt = dep.replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
69
|
-
resolvedPath = files.find((f) => {
|
|
70
|
-
const fWithoutExt = f.replace(/\.(ts|tsx|js|jsx)$/, "");
|
|
71
|
-
return fWithoutExt === depWithoutExt || fWithoutExt.endsWith(`/${depWithoutExt}`);
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
if (resolvedPath && resolvedPath !== file) {
|
|
75
|
-
dependencyGraph.get(file)?.push(resolvedPath);
|
|
76
|
-
reverseGraph.get(resolvedPath)?.push(file);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
} catch (err) {
|
|
80
|
-
void err;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const fileMetrics = files.map((file) => {
|
|
84
|
-
const fanOut = dependencyGraph.get(file)?.length || 0;
|
|
85
|
-
const fanIn = reverseGraph.get(file)?.length || 0;
|
|
86
|
-
return { file, fanOut, fanIn };
|
|
87
|
-
});
|
|
88
|
-
const riskResult = calculateChangeAmplification({ files: fileMetrics });
|
|
89
|
-
let finalScore = riskResult.score;
|
|
90
|
-
if (finalScore === 0 && files.length > 0 && riskResult.rating !== "explosive") {
|
|
91
|
-
finalScore = 10;
|
|
92
|
-
}
|
|
93
|
-
const results = [];
|
|
94
|
-
const getLevel = (s) => {
|
|
95
|
-
if (s === Severity.Critical || s === "critical") return 4;
|
|
96
|
-
if (s === Severity.Major || s === "major") return 3;
|
|
97
|
-
if (s === Severity.Minor || s === "minor") return 2;
|
|
98
|
-
if (s === Severity.Info || s === "info") return 1;
|
|
99
|
-
return 0;
|
|
100
|
-
};
|
|
101
|
-
for (const hotspot of riskResult.hotspots) {
|
|
102
|
-
const issues = [];
|
|
103
|
-
if (hotspot.amplificationFactor > 20) {
|
|
104
|
-
issues.push({
|
|
105
|
-
type: IssueType.ChangeAmplification,
|
|
106
|
-
severity: hotspot.amplificationFactor > 40 ? Severity.Critical : Severity.Major,
|
|
107
|
-
message: `High change amplification detected (Factor: ${hotspot.amplificationFactor}). Changes here cascade heavily.`,
|
|
108
|
-
location: { file: hotspot.file, line: 1 },
|
|
109
|
-
suggestion: `Reduce coupling. Fan-out is ${hotspot.fanOut}, Fan-in is ${hotspot.fanIn}.`
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
if (hotspot.amplificationFactor > 5) {
|
|
113
|
-
results.push({
|
|
114
|
-
fileName: hotspot.file,
|
|
115
|
-
issues,
|
|
116
|
-
metrics: {
|
|
117
|
-
aiSignalClarityScore: 100 - hotspot.amplificationFactor
|
|
118
|
-
// Just a rough score
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return {
|
|
124
|
-
summary: {
|
|
125
|
-
totalFiles: files.length,
|
|
126
|
-
totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
|
|
127
|
-
criticalIssues: results.reduce(
|
|
128
|
-
(sum, r) => sum + r.issues.filter((i) => getLevel(i.severity) === 4).length,
|
|
129
|
-
0
|
|
130
|
-
),
|
|
131
|
-
majorIssues: results.reduce(
|
|
132
|
-
(sum, r) => sum + r.issues.filter((i) => getLevel(i.severity) === 3).length,
|
|
133
|
-
0
|
|
134
|
-
),
|
|
135
|
-
score: finalScore,
|
|
136
|
-
rating: riskResult.rating,
|
|
137
|
-
recommendations: riskResult.recommendations
|
|
138
|
-
},
|
|
139
|
-
results
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export {
|
|
144
|
-
__require,
|
|
145
|
-
analyzeChangeAmplification
|
|
146
|
-
};
|