@aiready/change-amplification 0.11.17 → 0.11.21

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.
@@ -0,0 +1,210 @@
1
+ /* eslint-disable */
2
+ var addSorting = (function() {
3
+ 'use strict';
4
+ var cols,
5
+ currentSort = {
6
+ index: 0,
7
+ desc: false
8
+ };
9
+
10
+ // returns the summary table element
11
+ function getTable() {
12
+ return document.querySelector('.coverage-summary');
13
+ }
14
+ // returns the thead element of the summary table
15
+ function getTableHeader() {
16
+ return getTable().querySelector('thead tr');
17
+ }
18
+ // returns the tbody element of the summary table
19
+ function getTableBody() {
20
+ return getTable().querySelector('tbody');
21
+ }
22
+ // returns the th element for nth column
23
+ function getNthColumn(n) {
24
+ return getTableHeader().querySelectorAll('th')[n];
25
+ }
26
+
27
+ function onFilterInput() {
28
+ const searchValue = document.getElementById('fileSearch').value;
29
+ const rows = document.getElementsByTagName('tbody')[0].children;
30
+
31
+ // Try to create a RegExp from the searchValue. If it fails (invalid regex),
32
+ // it will be treated as a plain text search
33
+ let searchRegex;
34
+ try {
35
+ searchRegex = new RegExp(searchValue, 'i'); // 'i' for case-insensitive
36
+ } catch (error) {
37
+ searchRegex = null;
38
+ }
39
+
40
+ for (let i = 0; i < rows.length; i++) {
41
+ const row = rows[i];
42
+ let isMatch = false;
43
+
44
+ if (searchRegex) {
45
+ // If a valid regex was created, use it for matching
46
+ isMatch = searchRegex.test(row.textContent);
47
+ } else {
48
+ // Otherwise, fall back to the original plain text search
49
+ isMatch = row.textContent
50
+ .toLowerCase()
51
+ .includes(searchValue.toLowerCase());
52
+ }
53
+
54
+ row.style.display = isMatch ? '' : 'none';
55
+ }
56
+ }
57
+
58
+ // loads the search box
59
+ function addSearchBox() {
60
+ var template = document.getElementById('filterTemplate');
61
+ var templateClone = template.content.cloneNode(true);
62
+ templateClone.getElementById('fileSearch').oninput = onFilterInput;
63
+ template.parentElement.appendChild(templateClone);
64
+ }
65
+
66
+ // loads all columns
67
+ function loadColumns() {
68
+ var colNodes = getTableHeader().querySelectorAll('th'),
69
+ colNode,
70
+ cols = [],
71
+ col,
72
+ i;
73
+
74
+ for (i = 0; i < colNodes.length; i += 1) {
75
+ colNode = colNodes[i];
76
+ col = {
77
+ key: colNode.getAttribute('data-col'),
78
+ sortable: !colNode.getAttribute('data-nosort'),
79
+ type: colNode.getAttribute('data-type') || 'string'
80
+ };
81
+ cols.push(col);
82
+ if (col.sortable) {
83
+ col.defaultDescSort = col.type === 'number';
84
+ colNode.innerHTML =
85
+ colNode.innerHTML + '<span class="sorter"></span>';
86
+ }
87
+ }
88
+ return cols;
89
+ }
90
+ // attaches a data attribute to every tr element with an object
91
+ // of data values keyed by column name
92
+ function loadRowData(tableRow) {
93
+ var tableCols = tableRow.querySelectorAll('td'),
94
+ colNode,
95
+ col,
96
+ data = {},
97
+ i,
98
+ val;
99
+ for (i = 0; i < tableCols.length; i += 1) {
100
+ colNode = tableCols[i];
101
+ col = cols[i];
102
+ val = colNode.getAttribute('data-value');
103
+ if (col.type === 'number') {
104
+ val = Number(val);
105
+ }
106
+ data[col.key] = val;
107
+ }
108
+ return data;
109
+ }
110
+ // loads all row data
111
+ function loadData() {
112
+ var rows = getTableBody().querySelectorAll('tr'),
113
+ i;
114
+
115
+ for (i = 0; i < rows.length; i += 1) {
116
+ rows[i].data = loadRowData(rows[i]);
117
+ }
118
+ }
119
+ // sorts the table using the data for the ith column
120
+ function sortByIndex(index, desc) {
121
+ var key = cols[index].key,
122
+ sorter = function(a, b) {
123
+ a = a.data[key];
124
+ b = b.data[key];
125
+ return a < b ? -1 : a > b ? 1 : 0;
126
+ },
127
+ finalSorter = sorter,
128
+ tableBody = document.querySelector('.coverage-summary tbody'),
129
+ rowNodes = tableBody.querySelectorAll('tr'),
130
+ rows = [],
131
+ i;
132
+
133
+ if (desc) {
134
+ finalSorter = function(a, b) {
135
+ return -1 * sorter(a, b);
136
+ };
137
+ }
138
+
139
+ for (i = 0; i < rowNodes.length; i += 1) {
140
+ rows.push(rowNodes[i]);
141
+ tableBody.removeChild(rowNodes[i]);
142
+ }
143
+
144
+ rows.sort(finalSorter);
145
+
146
+ for (i = 0; i < rows.length; i += 1) {
147
+ tableBody.appendChild(rows[i]);
148
+ }
149
+ }
150
+ // removes sort indicators for current column being sorted
151
+ function removeSortIndicators() {
152
+ var col = getNthColumn(currentSort.index),
153
+ cls = col.className;
154
+
155
+ cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
156
+ col.className = cls;
157
+ }
158
+ // adds sort indicators for current column being sorted
159
+ function addSortIndicators() {
160
+ getNthColumn(currentSort.index).className += currentSort.desc
161
+ ? ' sorted-desc'
162
+ : ' sorted';
163
+ }
164
+ // adds event listeners for all sorter widgets
165
+ function enableUI() {
166
+ var i,
167
+ el,
168
+ ithSorter = function ithSorter(i) {
169
+ var col = cols[i];
170
+
171
+ return function() {
172
+ var desc = col.defaultDescSort;
173
+
174
+ if (currentSort.index === i) {
175
+ desc = !currentSort.desc;
176
+ }
177
+ sortByIndex(i, desc);
178
+ removeSortIndicators();
179
+ currentSort.index = i;
180
+ currentSort.desc = desc;
181
+ addSortIndicators();
182
+ };
183
+ };
184
+ for (i = 0; i < cols.length; i += 1) {
185
+ if (cols[i].sortable) {
186
+ // add the click event handler on the th so users
187
+ // dont have to click on those tiny arrows
188
+ el = getNthColumn(i).querySelector('.sorter').parentElement;
189
+ if (el.addEventListener) {
190
+ el.addEventListener('click', ithSorter(i));
191
+ } else {
192
+ el.attachEvent('onclick', ithSorter(i));
193
+ }
194
+ }
195
+ }
196
+ }
197
+ // adds sorting functionality to the UI
198
+ return function() {
199
+ if (!getTable()) {
200
+ return;
201
+ }
202
+ cols = loadColumns();
203
+ loadData();
204
+ addSearchBox();
205
+ addSortIndicators();
206
+ enableUI();
207
+ };
208
+ })();
209
+
210
+ window.addEventListener('load', addSorting);
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { ToolProvider, Issue, IssueType, ScanOptions, AnalysisResult } from '@aiready/core';
1
+ import { ToolProvider, Issue, IssueType, ScanOptions, AnalysisResult, ToolScoringOutput } from '@aiready/core';
2
2
 
3
3
  /**
4
4
  * Change Amplification Tool Provider
@@ -27,4 +27,9 @@ interface ChangeAmplificationReport {
27
27
 
28
28
  declare function analyzeChangeAmplification(options: ChangeAmplificationOptions): Promise<ChangeAmplificationReport>;
29
29
 
30
- export { type ChangeAmplificationIssue, type ChangeAmplificationOptions, ChangeAmplificationProvider, type ChangeAmplificationReport, type FileChangeAmplificationResult, analyzeChangeAmplification };
30
+ /**
31
+ * Convert change amplification report into a ToolScoringOutput.
32
+ */
33
+ declare function calculateChangeAmplificationScore(report: ChangeAmplificationReport): ToolScoringOutput;
34
+
35
+ export { type ChangeAmplificationIssue, type ChangeAmplificationOptions, ChangeAmplificationProvider, type ChangeAmplificationReport, type FileChangeAmplificationResult, analyzeChangeAmplification, calculateChangeAmplificationScore };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { ToolProvider, Issue, IssueType, ScanOptions, AnalysisResult } from '@aiready/core';
1
+ import { ToolProvider, Issue, IssueType, ScanOptions, AnalysisResult, ToolScoringOutput } from '@aiready/core';
2
2
 
3
3
  /**
4
4
  * Change Amplification Tool Provider
@@ -27,4 +27,9 @@ interface ChangeAmplificationReport {
27
27
 
28
28
  declare function analyzeChangeAmplification(options: ChangeAmplificationOptions): Promise<ChangeAmplificationReport>;
29
29
 
30
- export { type ChangeAmplificationIssue, type ChangeAmplificationOptions, ChangeAmplificationProvider, type ChangeAmplificationReport, type FileChangeAmplificationResult, analyzeChangeAmplification };
30
+ /**
31
+ * Convert change amplification report into a ToolScoringOutput.
32
+ */
33
+ declare function calculateChangeAmplificationScore(report: ChangeAmplificationReport): ToolScoringOutput;
34
+
35
+ export { type ChangeAmplificationIssue, type ChangeAmplificationOptions, ChangeAmplificationProvider, type ChangeAmplificationReport, type FileChangeAmplificationResult, analyzeChangeAmplification, calculateChangeAmplificationScore };
package/dist/index.js CHANGED
@@ -31,10 +31,11 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  ChangeAmplificationProvider: () => ChangeAmplificationProvider,
34
- analyzeChangeAmplification: () => analyzeChangeAmplification
34
+ analyzeChangeAmplification: () => analyzeChangeAmplification,
35
+ calculateChangeAmplificationScore: () => calculateChangeAmplificationScore
35
36
  });
36
37
  module.exports = __toCommonJS(index_exports);
37
- var import_core3 = require("@aiready/core");
38
+ var import_core4 = require("@aiready/core");
38
39
 
39
40
  // src/provider.ts
40
41
  var import_core2 = require("@aiready/core");
@@ -205,10 +206,40 @@ var ChangeAmplificationProvider = {
205
206
  defaultWeight: 8
206
207
  };
207
208
 
209
+ // src/scoring.ts
210
+ var import_core3 = require("@aiready/core");
211
+ function calculateChangeAmplificationScore(report) {
212
+ const { summary } = report;
213
+ const factors = [
214
+ {
215
+ name: "Graph Stability",
216
+ impact: Math.round(summary.score - 50),
217
+ description: summary.score < 30 ? "High coupling detected in core modules" : "Stable dependency structure"
218
+ }
219
+ ];
220
+ const recommendations = summary.recommendations.map((rec) => ({
221
+ action: rec,
222
+ estimatedImpact: 10,
223
+ priority: summary.score < 50 ? "high" : "medium"
224
+ }));
225
+ return {
226
+ toolName: import_core3.ToolName.ChangeAmplification,
227
+ score: summary.score,
228
+ rawMetrics: {
229
+ totalFiles: summary.totalFiles,
230
+ totalIssues: summary.totalIssues,
231
+ rating: summary.rating
232
+ },
233
+ factors,
234
+ recommendations
235
+ };
236
+ }
237
+
208
238
  // src/index.ts
209
- import_core3.ToolRegistry.register(ChangeAmplificationProvider);
239
+ import_core4.ToolRegistry.register(ChangeAmplificationProvider);
210
240
  // Annotate the CommonJS export names for ESM import in node:
211
241
  0 && (module.exports = {
212
242
  ChangeAmplificationProvider,
213
- analyzeChangeAmplification
243
+ analyzeChangeAmplification,
244
+ calculateChangeAmplificationScore
214
245
  });
package/dist/index.mjs CHANGED
@@ -46,9 +46,39 @@ var ChangeAmplificationProvider = {
46
46
  defaultWeight: 8
47
47
  };
48
48
 
49
+ // src/scoring.ts
50
+ import { ToolName as ToolName2 } from "@aiready/core";
51
+ function calculateChangeAmplificationScore(report) {
52
+ const { summary } = report;
53
+ const factors = [
54
+ {
55
+ name: "Graph Stability",
56
+ impact: Math.round(summary.score - 50),
57
+ description: summary.score < 30 ? "High coupling detected in core modules" : "Stable dependency structure"
58
+ }
59
+ ];
60
+ const recommendations = summary.recommendations.map((rec) => ({
61
+ action: rec,
62
+ estimatedImpact: 10,
63
+ priority: summary.score < 50 ? "high" : "medium"
64
+ }));
65
+ return {
66
+ toolName: ToolName2.ChangeAmplification,
67
+ score: summary.score,
68
+ rawMetrics: {
69
+ totalFiles: summary.totalFiles,
70
+ totalIssues: summary.totalIssues,
71
+ rating: summary.rating
72
+ },
73
+ factors,
74
+ recommendations
75
+ };
76
+ }
77
+
49
78
  // src/index.ts
50
79
  ToolRegistry.register(ChangeAmplificationProvider);
51
80
  export {
52
81
  ChangeAmplificationProvider,
53
- analyzeChangeAmplification
82
+ analyzeChangeAmplification,
83
+ calculateChangeAmplificationScore
54
84
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/change-amplification",
3
- "version": "0.11.17",
3
+ "version": "0.11.21",
4
4
  "description": "AI-Readiness: Change Amplification Detection",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -10,7 +10,7 @@
10
10
  "commander": "^14.0.0",
11
11
  "glob": "^13.0.0",
12
12
  "chalk": "^5.3.0",
13
- "@aiready/core": "0.21.17"
13
+ "@aiready/core": "0.21.21"
14
14
  },
15
15
  "devDependencies": {
16
16
  "@types/node": "^24.0.0",
@@ -0,0 +1,35 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { changeAmplificationAction } from '../cli';
3
+ import * as analyzer from '../analyzer';
4
+ import * as fs from 'fs';
5
+
6
+ vi.mock('../analyzer', () => ({
7
+ analyzeChangeAmplification: vi.fn().mockResolvedValue({
8
+ summary: {
9
+ score: 100,
10
+ rating: 'isolated',
11
+ criticalIssues: 0,
12
+ majorIssues: 0,
13
+ recommendations: [],
14
+ },
15
+ results: [],
16
+ }),
17
+ }));
18
+
19
+ vi.mock('fs', () => ({
20
+ writeFileSync: vi.fn(),
21
+ }));
22
+
23
+ describe('Change Amplification CLI', () => {
24
+ it('should run analysis and return scoring in json mode', async () => {
25
+ await changeAmplificationAction('.', { output: 'json' });
26
+ expect(fs.writeFileSync).toHaveBeenCalled();
27
+ });
28
+
29
+ it('should run analysis and print to console in default mode', async () => {
30
+ const consoleSpy = vi.spyOn(console, 'log').mockImplementation(() => {});
31
+ await changeAmplificationAction('.', { output: 'console' });
32
+ expect(consoleSpy).toHaveBeenCalled();
33
+ consoleSpy.mockRestore();
34
+ });
35
+ });
@@ -0,0 +1,42 @@
1
+ import { describe, it, expect, vi } from 'vitest';
2
+ import { ChangeAmplificationProvider } from '../provider';
3
+ import * as analyzer from '../analyzer';
4
+
5
+ vi.mock('../analyzer', () => ({
6
+ analyzeChangeAmplification: vi.fn(),
7
+ }));
8
+
9
+ describe('Change Amplification Provider', () => {
10
+ it('should analyze and return SpokeOutput', async () => {
11
+ vi.mocked(analyzer.analyzeChangeAmplification).mockResolvedValue({
12
+ summary: {
13
+ totalFiles: 1,
14
+ totalIssues: 0,
15
+ criticalIssues: 0,
16
+ majorIssues: 0,
17
+ score: 90,
18
+ rating: 'stable',
19
+ recommendations: [],
20
+ },
21
+ results: [],
22
+ });
23
+
24
+ const output = await ChangeAmplificationProvider.analyze({ rootDir: '.' });
25
+
26
+ expect(output.summary.totalFiles).toBe(1);
27
+ expect(output.metadata.toolName).toBe('change-amplification');
28
+ });
29
+
30
+ it('should score an output', () => {
31
+ const mockOutput = {
32
+ summary: { score: 85, recommendations: ['Decouple logic'] } as any,
33
+ results: [],
34
+ };
35
+
36
+ const scoring = ChangeAmplificationProvider.score(mockOutput as any, {
37
+ rootDir: '.',
38
+ });
39
+ expect(scoring.score).toBe(85);
40
+ expect(scoring.recommendations[0].action).toBe('Decouple logic');
41
+ });
42
+ });
@@ -0,0 +1,43 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { calculateChangeAmplificationScore } from '../scoring';
3
+ import { ChangeAmplificationReport } from '../types';
4
+ import { ToolName } from '@aiready/core';
5
+
6
+ describe('Change Amplification Scoring', () => {
7
+ const mockReport: ChangeAmplificationReport = {
8
+ summary: {
9
+ totalFiles: 100,
10
+ totalIssues: 5,
11
+ criticalIssues: 1,
12
+ majorIssues: 4,
13
+ score: 80,
14
+ rating: 'stable',
15
+ recommendations: ['Keep it up'],
16
+ },
17
+ results: [],
18
+ };
19
+
20
+ it('should map report to ToolScoringOutput correctly', () => {
21
+ const scoring = calculateChangeAmplificationScore(mockReport);
22
+
23
+ expect(scoring.toolName).toBe(ToolName.ChangeAmplification);
24
+ expect(scoring.score).toBe(80);
25
+ expect(scoring.factors[0].name).toBe('Graph Stability');
26
+ expect(scoring.factors[0].impact).toBe(30); // 80 - 50
27
+ });
28
+
29
+ it('should detect instability for low scores', () => {
30
+ const lowScoreReport: ChangeAmplificationReport = {
31
+ ...mockReport,
32
+ summary: {
33
+ ...mockReport.summary,
34
+ score: 20,
35
+ rating: 'explosive',
36
+ },
37
+ };
38
+
39
+ const scoring = calculateChangeAmplificationScore(lowScoreReport);
40
+ expect(scoring.factors[0].description).toContain('High coupling');
41
+ expect(scoring.recommendations[0].priority).toBe('high');
42
+ });
43
+ });
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ import { ChangeAmplificationProvider } from './provider';
5
5
  ToolRegistry.register(ChangeAmplificationProvider);
6
6
 
7
7
  export { analyzeChangeAmplification } from './analyzer';
8
+ export { calculateChangeAmplificationScore } from './scoring';
8
9
  export { ChangeAmplificationProvider };
9
10
  export type {
10
11
  ChangeAmplificationOptions,
package/src/scoring.ts ADDED
@@ -0,0 +1,42 @@
1
+ import { ToolName } from '@aiready/core';
2
+ import type { ToolScoringOutput } from '@aiready/core';
3
+ import type { ChangeAmplificationReport } from './types';
4
+
5
+ /**
6
+ * Convert change amplification report into a ToolScoringOutput.
7
+ */
8
+ export function calculateChangeAmplificationScore(
9
+ report: ChangeAmplificationReport
10
+ ): ToolScoringOutput {
11
+ const { summary } = report;
12
+
13
+ const factors: ToolScoringOutput['factors'] = [
14
+ {
15
+ name: 'Graph Stability',
16
+ impact: Math.round(summary.score - 50),
17
+ description:
18
+ summary.score < 30
19
+ ? 'High coupling detected in core modules'
20
+ : 'Stable dependency structure',
21
+ },
22
+ ];
23
+
24
+ const recommendations: ToolScoringOutput['recommendations'] =
25
+ summary.recommendations.map((rec) => ({
26
+ action: rec,
27
+ estimatedImpact: 10,
28
+ priority: summary.score < 50 ? 'high' : 'medium',
29
+ }));
30
+
31
+ return {
32
+ toolName: ToolName.ChangeAmplification,
33
+ score: summary.score,
34
+ rawMetrics: {
35
+ totalFiles: summary.totalFiles,
36
+ totalIssues: summary.totalIssues,
37
+ rating: summary.rating,
38
+ },
39
+ factors,
40
+ recommendations,
41
+ };
42
+ }