@aiready/change-amplification 0.14.8 → 0.14.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.
@@ -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
- };
@@ -1,126 +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
- for (const dep of dependencies) {
46
- const depDir = path.dirname(file);
47
- const resolvedPath = files.find((f) => {
48
- if (dep.startsWith(".")) {
49
- return f.startsWith(path.resolve(depDir, dep));
50
- } else {
51
- return f.includes(dep);
52
- }
53
- });
54
- if (resolvedPath) {
55
- dependencyGraph.get(file)?.push(resolvedPath);
56
- reverseGraph.get(resolvedPath)?.push(file);
57
- }
58
- }
59
- } catch (err) {
60
- void err;
61
- }
62
- }
63
- const fileMetrics = files.map((file) => {
64
- const fanOut = dependencyGraph.get(file)?.length || 0;
65
- const fanIn = reverseGraph.get(file)?.length || 0;
66
- return { file, fanOut, fanIn };
67
- });
68
- const riskResult = calculateChangeAmplification({ files: fileMetrics });
69
- let finalScore = riskResult.score;
70
- if (finalScore === 0 && files.length > 0 && riskResult.rating !== "explosive") {
71
- finalScore = 10;
72
- }
73
- const results = [];
74
- const getLevel = (s) => {
75
- if (s === Severity.Critical || s === "critical") return 4;
76
- if (s === Severity.Major || s === "major") return 3;
77
- if (s === Severity.Minor || s === "minor") return 2;
78
- if (s === Severity.Info || s === "info") return 1;
79
- return 0;
80
- };
81
- for (const hotspot of riskResult.hotspots) {
82
- const issues = [];
83
- if (hotspot.amplificationFactor > 20) {
84
- issues.push({
85
- type: IssueType.ChangeAmplification,
86
- severity: hotspot.amplificationFactor > 40 ? Severity.Critical : Severity.Major,
87
- message: `High change amplification detected (Factor: ${hotspot.amplificationFactor}). Changes here cascade heavily.`,
88
- location: { file: hotspot.file, line: 1 },
89
- suggestion: `Reduce coupling. Fan-out is ${hotspot.fanOut}, Fan-in is ${hotspot.fanIn}.`
90
- });
91
- }
92
- if (hotspot.amplificationFactor > 5) {
93
- results.push({
94
- fileName: hotspot.file,
95
- issues,
96
- metrics: {
97
- aiSignalClarityScore: 100 - hotspot.amplificationFactor
98
- // Just a rough score
99
- }
100
- });
101
- }
102
- }
103
- return {
104
- summary: {
105
- totalFiles: files.length,
106
- totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
107
- criticalIssues: results.reduce(
108
- (sum, r) => sum + r.issues.filter((i) => getLevel(i.severity) === 4).length,
109
- 0
110
- ),
111
- majorIssues: results.reduce(
112
- (sum, r) => sum + r.issues.filter((i) => getLevel(i.severity) === 3).length,
113
- 0
114
- ),
115
- score: finalScore,
116
- rating: riskResult.rating,
117
- recommendations: riskResult.recommendations
118
- },
119
- results
120
- };
121
- }
122
-
123
- export {
124
- __require,
125
- analyzeChangeAmplification
126
- };
@@ -1,117 +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
- let processed = 0;
38
- for (const file of files) {
39
- processed++;
40
- options.onProgress?.(processed, files.length, `change-amplification: analyzing ${file.substring(rootDir.length + 1)}`);
41
- try {
42
- const parser = getParser(file);
43
- if (!parser) continue;
44
- const content = fs.readFileSync(file, "utf8");
45
- const parseResult = parser.parse(content, file);
46
- const dependencies = parseResult.imports.map((i) => i.source);
47
- for (const dep of dependencies) {
48
- const depDir = path.dirname(file);
49
- const resolvedPath = files.find((f) => {
50
- if (dep.startsWith(".")) {
51
- return f.startsWith(path.resolve(depDir, dep));
52
- } else {
53
- return f.includes(dep);
54
- }
55
- });
56
- if (resolvedPath) {
57
- dependencyGraph.get(file)?.push(resolvedPath);
58
- reverseGraph.get(resolvedPath)?.push(file);
59
- }
60
- }
61
- } catch (err) {
62
- void err;
63
- }
64
- }
65
- const fileMetrics = files.map((file) => {
66
- const fanOut = dependencyGraph.get(file)?.length || 0;
67
- const fanIn = reverseGraph.get(file)?.length || 0;
68
- return { file, fanOut, fanIn };
69
- });
70
- const riskResult = calculateChangeAmplification({ files: fileMetrics });
71
- const results = [];
72
- for (const hotspot of riskResult.hotspots) {
73
- const issues = [];
74
- if (hotspot.amplificationFactor > 20) {
75
- issues.push({
76
- type: "change-amplification",
77
- severity: hotspot.amplificationFactor > 40 ? "critical" : "major",
78
- message: `High change amplification detected (Factor: ${hotspot.amplificationFactor}). Changes here cascade heavily.`,
79
- location: { file: hotspot.file, line: 1 },
80
- suggestion: `Reduce coupling. Fan-out is ${hotspot.fanOut}, Fan-in is ${hotspot.fanIn}.`
81
- });
82
- }
83
- if (hotspot.amplificationFactor > 5) {
84
- results.push({
85
- fileName: hotspot.file,
86
- issues,
87
- metrics: {
88
- aiSignalClarityScore: 100 - hotspot.amplificationFactor
89
- // Just a rough score
90
- }
91
- });
92
- }
93
- }
94
- return {
95
- summary: {
96
- totalFiles: files.length,
97
- totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
98
- criticalIssues: results.reduce(
99
- (sum, r) => sum + r.issues.filter((i) => i.severity === "critical").length,
100
- 0
101
- ),
102
- majorIssues: results.reduce(
103
- (sum, r) => sum + r.issues.filter((i) => i.severity === "major").length,
104
- 0
105
- ),
106
- score: riskResult.score,
107
- rating: riskResult.rating,
108
- recommendations: riskResult.recommendations
109
- },
110
- results
111
- };
112
- }
113
-
114
- export {
115
- __require,
116
- analyzeChangeAmplification
117
- };
@@ -1,103 +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, { 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 parser = getParser(file);
36
- if (!parser) continue;
37
- const content = fs.readFileSync(file, "utf8");
38
- const parseResult = parser.parse(content, file);
39
- const dependencies = parseResult.imports.map((i) => i.source);
40
- for (const dep of dependencies) {
41
- const depDir = path.dirname(file);
42
- const resolvedPath = files.find((f) => {
43
- if (dep.startsWith(".")) {
44
- return f.startsWith(path.resolve(depDir, dep));
45
- } else {
46
- return f.includes(dep);
47
- }
48
- });
49
- if (resolvedPath) {
50
- dependencyGraph.get(file)?.push(resolvedPath);
51
- reverseGraph.get(resolvedPath)?.push(file);
52
- }
53
- }
54
- } catch (err) {
55
- }
56
- }
57
- const fileMetrics = files.map((file) => {
58
- const fanOut = dependencyGraph.get(file)?.length || 0;
59
- const fanIn = reverseGraph.get(file)?.length || 0;
60
- return { file, fanOut, fanIn };
61
- });
62
- const riskResult = calculateChangeAmplification({ files: fileMetrics });
63
- const results = [];
64
- for (const hotspot of riskResult.hotspots) {
65
- const issues = [];
66
- if (hotspot.amplificationFactor > 20) {
67
- issues.push({
68
- type: "change-amplification",
69
- severity: hotspot.amplificationFactor > 40 ? "critical" : "major",
70
- message: `High change amplification detected (Factor: ${hotspot.amplificationFactor}). Changes here cascade heavily.`,
71
- location: { file: hotspot.file, line: 1 },
72
- suggestion: `Reduce coupling. Fan-out is ${hotspot.fanOut}, Fan-in is ${hotspot.fanIn}.`
73
- });
74
- }
75
- if (hotspot.amplificationFactor > 5) {
76
- results.push({
77
- fileName: hotspot.file,
78
- issues,
79
- metrics: {
80
- aiSignalClarityScore: 100 - hotspot.amplificationFactor
81
- // Just a rough score
82
- }
83
- });
84
- }
85
- }
86
- return {
87
- summary: {
88
- totalFiles: files.length,
89
- totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
90
- criticalIssues: results.reduce((sum, r) => sum + r.issues.filter((i) => i.severity === "critical").length, 0),
91
- majorIssues: results.reduce((sum, r) => sum + r.issues.filter((i) => i.severity === "major").length, 0),
92
- score: riskResult.score,
93
- rating: riskResult.rating,
94
- recommendations: riskResult.recommendations
95
- },
96
- results
97
- };
98
- }
99
-
100
- export {
101
- __require,
102
- analyzeChangeAmplification
103
- };
@@ -1,129 +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
- const enumMap = {
70
- [Severity.Critical]: 4,
71
- [Severity.Major]: 3,
72
- [Severity.Minor]: 2,
73
- [Severity.Info]: 1
74
- };
75
- const stringMap = {
76
- critical: 4,
77
- major: 3,
78
- minor: 2,
79
- info: 1
80
- };
81
- if (typeof s === "string") return stringMap[s.toLowerCase()] ?? 0;
82
- return enumMap[s] ?? 0;
83
- };
84
- for (const hotspot of riskResult.hotspots) {
85
- const issues = [];
86
- if (hotspot.amplificationFactor > 20) {
87
- issues.push({
88
- type: IssueType.ChangeAmplification,
89
- severity: hotspot.amplificationFactor > 40 ? Severity.Critical : Severity.Major,
90
- message: `High change amplification detected (Factor: ${hotspot.amplificationFactor}). Changes here cascade heavily.`,
91
- location: { file: hotspot.file, line: 1 },
92
- suggestion: `Reduce coupling. Fan-out is ${hotspot.fanOut}, Fan-in is ${hotspot.fanIn}.`
93
- });
94
- }
95
- if (hotspot.amplificationFactor > 5) {
96
- results.push({
97
- fileName: hotspot.file,
98
- issues,
99
- metrics: {
100
- aiSignalClarityScore: 100 - hotspot.amplificationFactor
101
- // Just a rough score
102
- }
103
- });
104
- }
105
- }
106
- return {
107
- summary: {
108
- totalFiles: files.length,
109
- totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
110
- criticalIssues: results.reduce(
111
- (sum, r) => sum + r.issues.filter((i) => getLevel(i.severity) === 4).length,
112
- 0
113
- ),
114
- majorIssues: results.reduce(
115
- (sum, r) => sum + r.issues.filter((i) => getLevel(i.severity) === 3).length,
116
- 0
117
- ),
118
- score: riskResult.score,
119
- rating: riskResult.rating,
120
- recommendations: riskResult.recommendations
121
- },
122
- results
123
- };
124
- }
125
-
126
- export {
127
- __require,
128
- analyzeChangeAmplification
129
- };