@aiready/change-amplification 0.1.5 → 0.1.8

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,6 +1,6 @@
1
1
 
2
2
  
3
- > @aiready/change-amplification@0.1.5 build /Users/pengcao/projects/aiready/packages/change-amplification
3
+ > @aiready/change-amplification@0.1.8 build /Users/pengcao/projects/aiready/packages/change-amplification
4
4
  > tsup src/index.ts src/cli.ts --format cjs,esm --dts
5
5
 
6
6
  CLI Building entry: src/cli.ts, src/index.ts
@@ -10,7 +10,7 @@
10
10
  CJS Build start
11
11
  ESM Build start
12
12
 
13
- [2:33:40 PM]  WARN  ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
13
+ [12:55:24 AM]  WARN  ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
14
14
 
15
15
  package.json:33:6:
16
16
   33 │ "types": "./dist/index.d.ts"
@@ -31,7 +31,7 @@
31
31
 
32
32
 
33
33
 
34
- [2:33:42 PM]  WARN  ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
34
+ [12:55:24 AM]  WARN  ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
35
35
 
36
36
  package.json:38:6:
37
37
   38 │ "types": "./dist/cli.d.ts"
@@ -51,8 +51,12 @@
51
51
 
52
52
 
53
53
 
54
+ ESM dist/index.mjs 110.00 B
55
+ ESM dist/cli.mjs 2.78 KB
56
+ ESM dist/chunk-MARO4FT6.mjs 3.52 KB
57
+ ESM ⚡️ Build success in 440ms
54
58
 
55
- [2:33:42 PM]  WARN  ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
59
+ [12:55:25 AM]  WARN  ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
56
60
 
57
61
  package.json:33:6:
58
62
   33 │ "types": "./dist/index.d.ts"
@@ -73,7 +77,7 @@
73
77
 
74
78
 
75
79
 
76
- [2:33:42 PM]  WARN  ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
80
+ [12:55:25 AM]  WARN  ▲ [WARNING] The condition "types" here will never be used as it comes after both "import" and "require" [package.json]
77
81
 
78
82
  package.json:38:6:
79
83
   38 │ "types": "./dist/cli.d.ts"
@@ -93,16 +97,12 @@
93
97
 
94
98
 
95
99
 
96
- CJS dist/index.js 5.13 KB
97
- CJS dist/cli.js 7.94 KB
98
- CJS ⚡️ Build success in 2825ms
99
- ESM dist/chunk-VW57ZQRN.mjs 3.83 KB
100
- ESM dist/index.mjs 110.00 B
101
- ESM dist/cli.mjs 2.72 KB
102
- ESM ⚡️ Build success in 2871ms
100
+ CJS dist/index.js 4.79 KB
101
+ CJS dist/cli.js 7.65 KB
102
+ CJS ⚡️ Build success in 631ms
103
103
  DTS Build start
104
- DTS ⚡️ Build success in 70027ms
104
+ DTS ⚡️ Build success in 10596ms
105
105
  DTS dist/cli.d.ts 152.00 B
106
- DTS dist/index.d.ts 1013.00 B
106
+ DTS dist/index.d.ts 999.00 B
107
107
  DTS dist/cli.d.mts 152.00 B
108
- DTS dist/index.d.mts 1013.00 B
108
+ DTS dist/index.d.mts 999.00 B
@@ -0,0 +1,5 @@
1
+
2
+ 
3
+ > @aiready/change-amplification@0.1.6 lint /Users/pengcao/projects/aiready/packages/change-amplification
4
+ > eslint src --ext .ts
5
+
@@ -1,16 +1,16 @@
1
1
 
2
2
  
3
- > @aiready/change-amplification@0.1.5 test /Users/pengcao/projects/aiready/packages/change-amplification
3
+ > @aiready/change-amplification@0.1.8 test /Users/pengcao/projects/aiready/packages/change-amplification
4
4
  > vitest run
5
5
 
6
+ [?25l
7
+  RUN  v4.0.18 /Users/pengcao/projects/aiready/packages/change-amplification
6
8
 
7
-  RUN  v1.6.1 /Users/pengcao/projects/aiready/packages/change-amplification
8
-
9
- ✓ src/__tests__/dummy.test.ts  (1 test) 6ms
9
+ ✓ src/__tests__/dummy.test.ts (1 test) 13ms
10
10
 
11
11
   Test Files  1 passed (1)
12
12
   Tests  1 passed (1)
13
-  Start at  14:38:44
14
-  Duration  12.16s (transform 3.05s, setup 42ms, collect 3.17s, tests 6ms, environment 0ms, prepare 5.23s)
13
+  Start at  00:56:24
14
+  Duration  1.16s (transform 306ms, setup 0ms, import 474ms, tests 13ms, environment 0ms)
15
15
 
16
16
  [?25h
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
 
8
8
  ## Overview
9
9
 
10
- High architectural coupling is one of the leading causes of AI agent failure. When an agent modifies a "bottleneck" file with dozens of dependents, the resulting cascade of breakages often exceeds the agent's context window or reasoning capacity.
10
+ High architectural coupling is one of the leading causes of AI agent failure. When an agent modifies a "bottleneck" file with dozens of dependents, the resulting cascade of breakages often exceeds the agent's context window or reasoning capacity.
11
11
 
12
12
  The **Change Amplification** analyzer computes graph metrics (fan-in, fan-out, and centrality) to identify these high-risk areas before they cause an "edit explosion."
13
13
 
@@ -0,0 +1,114 @@
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
+ };
@@ -0,0 +1,112 @@
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
+ };
@@ -0,0 +1,117 @@
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
+ };
package/dist/cli.js CHANGED
@@ -42,31 +42,29 @@ var fs2 = __toESM(require("fs"));
42
42
  // src/analyzer.ts
43
43
  var fs = __toESM(require("fs"));
44
44
  var path = __toESM(require("path"));
45
- var import_glob = require("glob");
46
45
  var import_core = require("@aiready/core");
47
- var import_core2 = require("@aiready/core");
48
- function collectFiles(dir, options) {
49
- const includePatterns = options.include && options.include.length > 0 ? options.include : ["**/*.{ts,tsx,js,jsx,py,go}"];
50
- const excludePatterns = options.exclude && options.exclude.length > 0 ? options.exclude : ["**/node_modules/**", "**/dist/**", "**/.git/**"];
51
- let matchedFiles = [];
52
- for (const pattern of includePatterns) {
53
- const files = (0, import_glob.globSync)(pattern, { cwd: dir, ignore: excludePatterns, absolute: true });
54
- matchedFiles = matchedFiles.concat(files);
55
- }
56
- return [...new Set(matchedFiles)];
57
- }
58
46
  async function analyzeChangeAmplification(options) {
59
47
  const rootDir = path.resolve(options.rootDir || ".");
60
- const files = collectFiles(rootDir, options);
48
+ const files = await (0, import_core.scanFiles)({
49
+ ...options,
50
+ include: options.include || ["**/*.{ts,tsx,js,jsx,py,go}"]
51
+ });
61
52
  const dependencyGraph = /* @__PURE__ */ new Map();
62
53
  const reverseGraph = /* @__PURE__ */ new Map();
63
54
  for (const file of files) {
64
55
  dependencyGraph.set(file, []);
65
56
  reverseGraph.set(file, []);
66
57
  }
58
+ let processed = 0;
67
59
  for (const file of files) {
60
+ processed++;
61
+ options.onProgress?.(
62
+ processed,
63
+ files.length,
64
+ `change-amplification: analyzing files`
65
+ );
68
66
  try {
69
- const parser = (0, import_core2.getParser)(file);
67
+ const parser = (0, import_core.getParser)(file);
70
68
  if (!parser) continue;
71
69
  const content = fs.readFileSync(file, "utf8");
72
70
  const parseResult = parser.parse(content, file);
@@ -86,6 +84,7 @@ async function analyzeChangeAmplification(options) {
86
84
  }
87
85
  }
88
86
  } catch (err) {
87
+ void err;
89
88
  }
90
89
  }
91
90
  const fileMetrics = files.map((file) => {
@@ -121,8 +120,14 @@ async function analyzeChangeAmplification(options) {
121
120
  summary: {
122
121
  totalFiles: files.length,
123
122
  totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
124
- criticalIssues: results.reduce((sum, r) => sum + r.issues.filter((i) => i.severity === "critical").length, 0),
125
- majorIssues: results.reduce((sum, r) => sum + r.issues.filter((i) => i.severity === "major").length, 0),
123
+ criticalIssues: results.reduce(
124
+ (sum, r) => sum + r.issues.filter((i) => i.severity === "critical").length,
125
+ 0
126
+ ),
127
+ majorIssues: results.reduce(
128
+ (sum, r) => sum + r.issues.filter((i) => i.severity === "major").length,
129
+ 0
130
+ ),
126
131
  score: riskResult.score,
127
132
  rating: riskResult.rating,
128
133
  recommendations: riskResult.recommendations
@@ -169,10 +174,17 @@ var changeAmplificationAction = async (directory, options) => {
169
174
  }
170
175
  }
171
176
  } else {
172
- console.log(import_chalk.default.green("\n\u2728 No change amplification issues found. Architecture is well contained."));
177
+ console.log(
178
+ import_chalk.default.green(
179
+ "\n\u2728 No change amplification issues found. Architecture is well contained."
180
+ )
181
+ );
173
182
  }
174
183
  } catch (error) {
175
- console.error(import_chalk.default.red("Error during change amplification analysis:"), error);
184
+ console.error(
185
+ import_chalk.default.red("Error during change amplification analysis:"),
186
+ error
187
+ );
176
188
  process.exit(1);
177
189
  }
178
190
  };
package/dist/cli.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import {
3
3
  __require,
4
4
  analyzeChangeAmplification
5
- } from "./chunk-VW57ZQRN.mjs";
5
+ } from "./chunk-MARO4FT6.mjs";
6
6
 
7
7
  // src/cli.ts
8
8
  import { Command } from "commander";
@@ -46,10 +46,17 @@ var changeAmplificationAction = async (directory, options) => {
46
46
  }
47
47
  }
48
48
  } else {
49
- console.log(chalk.green("\n\u2728 No change amplification issues found. Architecture is well contained."));
49
+ console.log(
50
+ chalk.green(
51
+ "\n\u2728 No change amplification issues found. Architecture is well contained."
52
+ )
53
+ );
50
54
  }
51
55
  } catch (error) {
52
- console.error(chalk.red("Error during change amplification analysis:"), error);
56
+ console.error(
57
+ chalk.red("Error during change amplification analysis:"),
58
+ error
59
+ );
53
60
  process.exit(1);
54
61
  }
55
62
  };
package/dist/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Issue, ScanOptions } from '@aiready/core';
2
2
 
3
- interface ChangeAmplificationOptions extends ScanOptions {
4
- }
3
+ type ChangeAmplificationOptions = ScanOptions;
5
4
  interface ChangeAmplificationIssue extends Issue {
6
5
  type: 'change-amplification';
7
6
  }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { Issue, ScanOptions } from '@aiready/core';
2
2
 
3
- interface ChangeAmplificationOptions extends ScanOptions {
4
- }
3
+ type ChangeAmplificationOptions = ScanOptions;
5
4
  interface ChangeAmplificationIssue extends Issue {
6
5
  type: 'change-amplification';
7
6
  }
package/dist/index.js CHANGED
@@ -37,31 +37,29 @@ module.exports = __toCommonJS(index_exports);
37
37
  // src/analyzer.ts
38
38
  var fs = __toESM(require("fs"));
39
39
  var path = __toESM(require("path"));
40
- var import_glob = require("glob");
41
40
  var import_core = require("@aiready/core");
42
- var import_core2 = require("@aiready/core");
43
- function collectFiles(dir, options) {
44
- const includePatterns = options.include && options.include.length > 0 ? options.include : ["**/*.{ts,tsx,js,jsx,py,go}"];
45
- const excludePatterns = options.exclude && options.exclude.length > 0 ? options.exclude : ["**/node_modules/**", "**/dist/**", "**/.git/**"];
46
- let matchedFiles = [];
47
- for (const pattern of includePatterns) {
48
- const files = (0, import_glob.globSync)(pattern, { cwd: dir, ignore: excludePatterns, absolute: true });
49
- matchedFiles = matchedFiles.concat(files);
50
- }
51
- return [...new Set(matchedFiles)];
52
- }
53
41
  async function analyzeChangeAmplification(options) {
54
42
  const rootDir = path.resolve(options.rootDir || ".");
55
- const files = collectFiles(rootDir, options);
43
+ const files = await (0, import_core.scanFiles)({
44
+ ...options,
45
+ include: options.include || ["**/*.{ts,tsx,js,jsx,py,go}"]
46
+ });
56
47
  const dependencyGraph = /* @__PURE__ */ new Map();
57
48
  const reverseGraph = /* @__PURE__ */ new Map();
58
49
  for (const file of files) {
59
50
  dependencyGraph.set(file, []);
60
51
  reverseGraph.set(file, []);
61
52
  }
53
+ let processed = 0;
62
54
  for (const file of files) {
55
+ processed++;
56
+ options.onProgress?.(
57
+ processed,
58
+ files.length,
59
+ `change-amplification: analyzing files`
60
+ );
63
61
  try {
64
- const parser = (0, import_core2.getParser)(file);
62
+ const parser = (0, import_core.getParser)(file);
65
63
  if (!parser) continue;
66
64
  const content = fs.readFileSync(file, "utf8");
67
65
  const parseResult = parser.parse(content, file);
@@ -81,6 +79,7 @@ async function analyzeChangeAmplification(options) {
81
79
  }
82
80
  }
83
81
  } catch (err) {
82
+ void err;
84
83
  }
85
84
  }
86
85
  const fileMetrics = files.map((file) => {
@@ -116,8 +115,14 @@ async function analyzeChangeAmplification(options) {
116
115
  summary: {
117
116
  totalFiles: files.length,
118
117
  totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
119
- criticalIssues: results.reduce((sum, r) => sum + r.issues.filter((i) => i.severity === "critical").length, 0),
120
- majorIssues: results.reduce((sum, r) => sum + r.issues.filter((i) => i.severity === "major").length, 0),
118
+ criticalIssues: results.reduce(
119
+ (sum, r) => sum + r.issues.filter((i) => i.severity === "critical").length,
120
+ 0
121
+ ),
122
+ majorIssues: results.reduce(
123
+ (sum, r) => sum + r.issues.filter((i) => i.severity === "major").length,
124
+ 0
125
+ ),
121
126
  score: riskResult.score,
122
127
  rating: riskResult.rating,
123
128
  recommendations: riskResult.recommendations
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  analyzeChangeAmplification
3
- } from "./chunk-VW57ZQRN.mjs";
3
+ } from "./chunk-MARO4FT6.mjs";
4
4
  export {
5
5
  analyzeChangeAmplification
6
6
  };
package/package.json CHANGED
@@ -1,23 +1,23 @@
1
1
  {
2
2
  "name": "@aiready/change-amplification",
3
- "version": "0.1.5",
3
+ "version": "0.1.8",
4
4
  "description": "AI-Readiness: Change Amplification Detection",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "dependencies": {
9
- "@typescript-eslint/typescript-estree": "^7.8.0",
10
- "commander": "^12.0.0",
11
- "glob": "^10.3.12",
9
+ "@typescript-eslint/typescript-estree": "^8.0.0",
10
+ "commander": "^14.0.0",
11
+ "glob": "^13.0.0",
12
12
  "chalk": "^5.3.0",
13
- "@aiready/core": "0.9.32"
13
+ "@aiready/core": "0.9.35"
14
14
  },
15
15
  "devDependencies": {
16
- "@types/node": "^20.12.7",
17
- "@typescript-eslint/types": "^7.8.0",
16
+ "@types/node": "^24.0.0",
17
+ "@typescript-eslint/types": "^8.0.0",
18
18
  "tsup": "^8.0.2",
19
19
  "typescript": "^5.4.5",
20
- "vitest": "^1.6.0"
20
+ "vitest": "^4.0.0"
21
21
  },
22
22
  "exports": {
23
23
  ".": {
package/src/analyzer.ts CHANGED
@@ -1,31 +1,30 @@
1
1
  import * as fs from 'fs';
2
2
  import * as path from 'path';
3
- import { globSync } from 'glob';
4
- import { calculateChangeAmplification } from '@aiready/core';
5
- import type { ChangeAmplificationOptions, ChangeAmplificationReport, FileChangeAmplificationResult, ChangeAmplificationIssue } from './types';
6
- import { getParser } from '@aiready/core';
7
-
8
- function collectFiles(dir: string, options: ChangeAmplificationOptions): string[] {
9
- const includePatterns = options.include && options.include.length > 0 ? options.include : ['**/*.{ts,tsx,js,jsx,py,go}'];
10
- const excludePatterns = options.exclude && options.exclude.length > 0 ? options.exclude : ['**/node_modules/**', '**/dist/**', '**/.git/**'];
11
-
12
- let matchedFiles: string[] = [];
13
- for (const pattern of includePatterns) {
14
- const files = globSync(pattern, { cwd: dir, ignore: excludePatterns, absolute: true });
15
- matchedFiles = matchedFiles.concat(files);
16
- }
17
- return [...new Set(matchedFiles)];
18
- }
3
+ import {
4
+ scanFiles,
5
+ calculateChangeAmplification,
6
+ getParser,
7
+ } from '@aiready/core';
8
+ import type {
9
+ ChangeAmplificationOptions,
10
+ ChangeAmplificationReport,
11
+ FileChangeAmplificationResult,
12
+ ChangeAmplificationIssue,
13
+ } from './types';
19
14
 
20
15
  export async function analyzeChangeAmplification(
21
- options: ChangeAmplificationOptions,
16
+ options: ChangeAmplificationOptions
22
17
  ): Promise<ChangeAmplificationReport> {
23
18
  const rootDir = path.resolve(options.rootDir || '.');
24
- const files = collectFiles(rootDir, options);
19
+ // Use core scanFiles which respects .gitignore recursively
20
+ const files = await scanFiles({
21
+ ...options,
22
+ include: options.include || ['**/*.{ts,tsx,js,jsx,py,go}'],
23
+ });
25
24
 
26
25
  // Compute graph metrics: fanIn and fanOut
27
26
  const dependencyGraph = new Map<string, string[]>(); // key: file, value: imported files
28
- const reverseGraph = new Map<string, string[]>(); // key: file, value: files that import it
27
+ const reverseGraph = new Map<string, string[]>(); // key: file, value: files that import it
29
28
 
30
29
  // Initialize graph
31
30
  for (const file of files) {
@@ -34,14 +33,22 @@ export async function analyzeChangeAmplification(
34
33
  }
35
34
 
36
35
  // Parse files to build dependency graph
36
+ let processed = 0;
37
37
  for (const file of files) {
38
+ processed++;
39
+ options.onProgress?.(
40
+ processed,
41
+ files.length,
42
+ `change-amplification: analyzing files`
43
+ );
44
+
38
45
  try {
39
46
  const parser = getParser(file);
40
47
  if (!parser) continue;
41
48
 
42
49
  const content = fs.readFileSync(file, 'utf8');
43
50
  const parseResult = parser.parse(content, file);
44
- const dependencies = parseResult.imports.map(i => i.source);
51
+ const dependencies = parseResult.imports.map((i) => i.source);
45
52
 
46
53
  for (const dep of dependencies) {
47
54
  // Resolve simple relative or absolute imports for the graph
@@ -49,7 +56,7 @@ export async function analyzeChangeAmplification(
49
56
  const depDir = path.dirname(file);
50
57
 
51
58
  // Find if this dependency resolves to one of our mapped files
52
- const resolvedPath = files.find(f => {
59
+ const resolvedPath = files.find((f) => {
53
60
  if (dep.startsWith('.')) {
54
61
  return f.startsWith(path.resolve(depDir, dep));
55
62
  } else {
@@ -63,11 +70,11 @@ export async function analyzeChangeAmplification(
63
70
  }
64
71
  }
65
72
  } catch (err) {
66
- // Ignore parse errors silently
73
+ void err;
67
74
  }
68
75
  }
69
76
 
70
- const fileMetrics = files.map(file => {
77
+ const fileMetrics = files.map((file) => {
71
78
  const fanOut = dependencyGraph.get(file)?.length || 0;
72
79
  const fanIn = reverseGraph.get(file)?.length || 0;
73
80
  return { file, fanOut, fanIn };
@@ -85,7 +92,7 @@ export async function analyzeChangeAmplification(
85
92
  severity: hotspot.amplificationFactor > 40 ? 'critical' : 'major',
86
93
  message: `High change amplification detected (Factor: ${hotspot.amplificationFactor}). Changes here cascade heavily.`,
87
94
  location: { file: hotspot.file, line: 1 },
88
- suggestion: `Reduce coupling. Fan-out is ${hotspot.fanOut}, Fan-in is ${hotspot.fanIn}.`
95
+ suggestion: `Reduce coupling. Fan-out is ${hotspot.fanOut}, Fan-in is ${hotspot.fanIn}.`,
89
96
  });
90
97
  }
91
98
 
@@ -96,7 +103,7 @@ export async function analyzeChangeAmplification(
96
103
  issues,
97
104
  metrics: {
98
105
  aiSignalClarityScore: 100 - hotspot.amplificationFactor, // Just a rough score
99
- }
106
+ },
100
107
  });
101
108
  }
102
109
  }
@@ -105,8 +112,15 @@ export async function analyzeChangeAmplification(
105
112
  summary: {
106
113
  totalFiles: files.length,
107
114
  totalIssues: results.reduce((sum, r) => sum + r.issues.length, 0),
108
- criticalIssues: results.reduce((sum, r) => sum + r.issues.filter(i => i.severity === 'critical').length, 0),
109
- majorIssues: results.reduce((sum, r) => sum + r.issues.filter(i => i.severity === 'major').length, 0),
115
+ criticalIssues: results.reduce(
116
+ (sum, r) =>
117
+ sum + r.issues.filter((i) => i.severity === 'critical').length,
118
+ 0
119
+ ),
120
+ majorIssues: results.reduce(
121
+ (sum, r) => sum + r.issues.filter((i) => i.severity === 'major').length,
122
+ 0
123
+ ),
110
124
  score: riskResult.score,
111
125
  rating: riskResult.rating,
112
126
  recommendations: riskResult.recommendations,
package/src/cli.ts CHANGED
@@ -6,7 +6,10 @@ import * as fs from 'fs';
6
6
  import { analyzeChangeAmplification } from './analyzer';
7
7
  import type { ChangeAmplificationOptions } from './types';
8
8
 
9
- export const changeAmplificationAction = async (directory: string, options: any) => {
9
+ export const changeAmplificationAction = async (
10
+ directory: string,
11
+ options: any
12
+ ) => {
10
13
  try {
11
14
  const resolvedDir = path.resolve(process.cwd(), directory);
12
15
  const finalOptions: ChangeAmplificationOptions = {
@@ -18,7 +21,8 @@ export const changeAmplificationAction = async (directory: string, options: any)
18
21
  const report = await analyzeChangeAmplification(finalOptions);
19
22
 
20
23
  if (options.output === 'json') {
21
- const outputPath = options.outputFile || `change-amplification-report-${Date.now()}.json`;
24
+ const outputPath =
25
+ options.outputFile || `change-amplification-report-${Date.now()}.json`;
22
26
  fs.writeFileSync(outputPath, JSON.stringify(report, null, 2));
23
27
  return;
24
28
  }
@@ -41,16 +45,24 @@ export const changeAmplificationAction = async (directory: string, options: any)
41
45
  for (const result of report.results) {
42
46
  console.log(`\n📄 ${chalk.cyan(result.fileName)}`);
43
47
  for (const issue of result.issues) {
44
- const color = issue.severity === 'critical' ? chalk.red : chalk.yellow;
48
+ const color =
49
+ issue.severity === 'critical' ? chalk.red : chalk.yellow;
45
50
  console.log(` ${color('■')} ${issue.message}`);
46
51
  console.log(` ${chalk.dim('Suggestion: ' + issue.suggestion)}`);
47
52
  }
48
53
  }
49
54
  } else {
50
- console.log(chalk.green('\n✨ No change amplification issues found. Architecture is well contained.'));
55
+ console.log(
56
+ chalk.green(
57
+ '\n✨ No change amplification issues found. Architecture is well contained.'
58
+ )
59
+ );
51
60
  }
52
61
  } catch (error) {
53
- console.error(chalk.red('Error during change amplification analysis:'), error);
62
+ console.error(
63
+ chalk.red('Error during change amplification analysis:'),
64
+ error
65
+ );
54
66
  process.exit(1);
55
67
  }
56
68
  };
package/src/types.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  import type { ScanOptions, Issue } from '@aiready/core';
2
2
 
3
- export interface ChangeAmplificationOptions extends ScanOptions {
4
- // Add any specific configurations needed for change amplification here
5
- }
3
+ export type ChangeAmplificationOptions = ScanOptions;
6
4
 
7
5
  export interface ChangeAmplificationIssue extends Issue {
8
6
  type: 'change-amplification';