@aiready/pattern-detect 0.17.8 → 0.17.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/dist/analyzer-entry/index.d.mts +1 -1
- package/dist/analyzer-entry/index.d.ts +1 -1
- package/dist/analyzer-entry/index.js +370 -135
- package/dist/analyzer-entry/index.mjs +4 -3
- package/dist/chunk-2P7BQHGR.mjs +306 -0
- package/dist/{chunk-VGMM3L3O.mjs → chunk-3EORD7DC.mjs} +1 -1
- package/dist/{chunk-GREN7X5H.mjs → chunk-4PVPQMRT.mjs} +2 -2
- package/dist/{chunk-RS73WLNI.mjs → chunk-6VDL7TAS.mjs} +5 -113
- package/dist/chunk-AQIP4JGM.mjs +283 -0
- package/dist/{chunk-JBUZ6YHE.mjs → chunk-B4NLWKPZ.mjs} +85 -9
- package/dist/chunk-IPBGVPUX.mjs +143 -0
- package/dist/chunk-LUUJOUK5.mjs +283 -0
- package/dist/chunk-P3BOCGVV.mjs +498 -0
- package/dist/{scoring-entry.js → chunk-PHJE6A3J.mjs} +20 -37
- package/dist/chunk-PQXOORR4.mjs +234 -0
- package/dist/{chunk-GLKAGFKX.mjs → chunk-RDR75DVI.mjs} +85 -9
- package/dist/chunk-SXVLRPMF.mjs +143 -0
- package/dist/{chunk-DNZS4ESD.mjs → chunk-SY7RX5YQ.mjs} +85 -9
- package/dist/{context-rules-entry.js → chunk-TIBF7KST.mjs} +81 -78
- package/dist/chunk-WYYSQX5M.mjs +467 -0
- package/dist/{chunk-I6ETJC7L.mjs → chunk-X553BOMI.mjs} +56 -26
- package/dist/{chunk-K7BO57OO.mjs → chunk-Y6OB7K34.mjs} +80 -4
- package/dist/chunk-YLVV6YZ5.mjs +143 -0
- package/dist/chunk-ZUWPFVJV.mjs +115 -0
- package/dist/chunk-ZZMONVPE.mjs +467 -0
- package/dist/cli.js +402 -167
- package/dist/cli.mjs +4 -3
- package/dist/context-rules-entry/index.d.mts +35 -1
- package/dist/context-rules-entry/index.d.ts +35 -1
- package/dist/context-rules-entry/index.js +194 -48
- package/dist/context-rules-entry/index.mjs +1 -1
- package/dist/detector-entry/index.js +192 -46
- package/dist/detector-entry/index.mjs +2 -2
- package/dist/{analyzer-entry-BVz-HnZd.d.mts → index-B-pnXpgn.d.mts} +10 -1
- package/dist/{index-BwuoiCNm.d.ts → index-CWgYOKaK.d.ts} +35 -16
- package/dist/{index-BVz-HnZd.d.mts → index-Dl4BrGIT.d.mts} +35 -16
- package/dist/{analyzer-entry-BwuoiCNm.d.ts → index-DqS2e0kK.d.ts} +10 -1
- package/dist/index.d.mts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +467 -214
- package/dist/index.mjs +37 -22
- package/dist/scoring-entry/index.js +7 -3
- package/dist/scoring-entry/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/analyzer-entry.d.mts +0 -100
- package/dist/analyzer-entry.d.ts +0 -100
- package/dist/analyzer-entry.js +0 -693
- package/dist/analyzer-entry.mjs +0 -12
- package/dist/chunk-262N2JB7.mjs +0 -497
- package/dist/chunk-2R7HOR5H.mjs +0 -777
- package/dist/chunk-3D7RVGHM.mjs +0 -64
- package/dist/chunk-3LS3E6MO.mjs +0 -508
- package/dist/chunk-3VRQYFW3.mjs +0 -782
- package/dist/chunk-3WK24ZOX.mjs +0 -860
- package/dist/chunk-3YYN6ZXN.mjs +0 -1038
- package/dist/chunk-4BPRGZRG.mjs +0 -1041
- package/dist/chunk-4UHDGB7U.mjs +0 -920
- package/dist/chunk-5LYDB7DY.mjs +0 -771
- package/dist/chunk-65G3HXLQ.mjs +0 -497
- package/dist/chunk-65UQ5J2J.mjs +0 -64
- package/dist/chunk-6JTVOBJX.mjs +0 -64
- package/dist/chunk-6OEHUI5J.mjs +0 -1045
- package/dist/chunk-6YUGU4P4.mjs +0 -914
- package/dist/chunk-7EJGNGXM.mjs +0 -771
- package/dist/chunk-7O2DUBSN.mjs +0 -1058
- package/dist/chunk-7S4AUL5S.mjs +0 -911
- package/dist/chunk-A76JUWER.mjs +0 -786
- package/dist/chunk-AJZUNNFH.mjs +0 -817
- package/dist/chunk-AXHGYYYZ.mjs +0 -404
- package/dist/chunk-BKRPSTT2.mjs +0 -64
- package/dist/chunk-BUBQ3W6W.mjs +0 -980
- package/dist/chunk-CCHM2VLK.mjs +0 -1051
- package/dist/chunk-CHFK6EBT.mjs +0 -419
- package/dist/chunk-CMT3MWWO.mjs +0 -948
- package/dist/chunk-CMWW24HW.mjs +0 -259
- package/dist/chunk-CTDBJP25.mjs +0 -1043
- package/dist/chunk-DGAKXYIP.mjs +0 -1041
- package/dist/chunk-DQSLTL7J.mjs +0 -788
- package/dist/chunk-DR5W7S3Z.mjs +0 -968
- package/dist/chunk-EFUKPMBE.mjs +0 -950
- package/dist/chunk-EVBFDILL.mjs +0 -927
- package/dist/chunk-EXORBAXR.mjs +0 -887
- package/dist/chunk-EZT3NZGB.mjs +0 -1057
- package/dist/chunk-FWUKMJEQ.mjs +0 -1133
- package/dist/chunk-GSJFORRO.mjs +0 -504
- package/dist/chunk-H4ADJYOG.mjs +0 -925
- package/dist/chunk-H5FB2USZ.mjs +0 -762
- package/dist/chunk-H73HEG7M.mjs +0 -670
- package/dist/chunk-HOS5Z2NC.mjs +0 -669
- package/dist/chunk-HXHQOQB5.mjs +0 -508
- package/dist/chunk-INEOYHUM.mjs +0 -911
- package/dist/chunk-INJ4SBTV.mjs +0 -754
- package/dist/chunk-J5CW6NYY.mjs +0 -64
- package/dist/chunk-JAFZCZAP.mjs +0 -776
- package/dist/chunk-JKVKOXYR.mjs +0 -407
- package/dist/chunk-JTHW7EYW.mjs +0 -1041
- package/dist/chunk-JWR3AHKO.mjs +0 -788
- package/dist/chunk-KC2CQMG2.mjs +0 -858
- package/dist/chunk-KDWGWBP5.mjs +0 -832
- package/dist/chunk-KPEK5REL.mjs +0 -919
- package/dist/chunk-KT6O2IAE.mjs +0 -861
- package/dist/chunk-KWMNN3TG.mjs +0 -391
- package/dist/chunk-LUA5FXSZ.mjs +0 -771
- package/dist/chunk-LYKRYBSM.mjs +0 -64
- package/dist/chunk-M4PQMW34.mjs +0 -480
- package/dist/chunk-MH6LBXZF.mjs +0 -816
- package/dist/chunk-MHU3CL4R.mjs +0 -64
- package/dist/chunk-MJWBS6SM.mjs +0 -1058
- package/dist/chunk-OFGMDX66.mjs +0 -402
- package/dist/chunk-P7B6Z4I2.mjs +0 -1043
- package/dist/chunk-PBCXSG7E.mjs +0 -658
- package/dist/chunk-PEEHSFDR.mjs +0 -1058
- package/dist/chunk-PSVG2NLH.mjs +0 -966
- package/dist/chunk-PWNQ6JZW.mjs +0 -508
- package/dist/chunk-QE4E3F7C.mjs +0 -410
- package/dist/chunk-QEP76HGK.mjs +0 -1039
- package/dist/chunk-QX2BQJEO.mjs +0 -1058
- package/dist/chunk-R2S73CVG.mjs +0 -503
- package/dist/chunk-RMGDSNLE.mjs +0 -770
- package/dist/chunk-S2KQFII2.mjs +0 -491
- package/dist/chunk-SLDK5PQK.mjs +0 -1129
- package/dist/chunk-SNSDVGWW.mjs +0 -783
- package/dist/chunk-SUUZMLPS.mjs +0 -391
- package/dist/chunk-SVCSIZ2A.mjs +0 -259
- package/dist/chunk-T2C6WS73.mjs +0 -670
- package/dist/chunk-TCG2G32F.mjs +0 -911
- package/dist/chunk-TGBZP7SB.mjs +0 -773
- package/dist/chunk-THF4RW63.mjs +0 -254
- package/dist/chunk-TJKDLVLN.mjs +0 -503
- package/dist/chunk-TXWPOVYU.mjs +0 -402
- package/dist/chunk-UB3CGOQ7.mjs +0 -64
- package/dist/chunk-UKIKN27B.mjs +0 -950
- package/dist/chunk-V5DP4FP6.mjs +0 -876
- package/dist/chunk-VRMXVYDZ.mjs +0 -419
- package/dist/chunk-WACZ5LFH.mjs +0 -1055
- package/dist/chunk-WC7CBAA7.mjs +0 -1058
- package/dist/chunk-WKBCNITM.mjs +0 -1072
- package/dist/chunk-WMOGJFME.mjs +0 -391
- package/dist/chunk-X4GR2N2M.mjs +0 -947
- package/dist/chunk-XCWY2DQY.mjs +0 -788
- package/dist/chunk-XJD35DS6.mjs +0 -1058
- package/dist/chunk-XNPID6FU.mjs +0 -391
- package/dist/chunk-XUUVS54V.mjs +0 -776
- package/dist/chunk-YCGV65F5.mjs +0 -508
- package/dist/chunk-YJYDBFT3.mjs +0 -780
- package/dist/chunk-YP3HEDQW.mjs +0 -859
- package/dist/chunk-YSDOUNJJ.mjs +0 -1142
- package/dist/chunk-Z6GBFFOV.mjs +0 -1040
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/context-rules-entry-y2uJSngh.d.mts +0 -60
- package/dist/context-rules-entry-y2uJSngh.d.ts +0 -60
- package/dist/context-rules-entry.d.mts +0 -55
- package/dist/context-rules-entry.d.ts +0 -55
- package/dist/context-rules-entry.mjs +0 -12
- package/dist/context-rules.d.ts +0 -41
- package/dist/context-rules.d.ts.map +0 -1
- package/dist/context-rules.js +0 -225
- package/dist/context-rules.js.map +0 -1
- package/dist/detector-entry.d.mts +0 -14
- package/dist/detector-entry.d.ts +0 -14
- package/dist/detector-entry.js +0 -301
- package/dist/detector-entry.mjs +0 -7
- package/dist/detector.d.ts +0 -40
- package/dist/detector.d.ts.map +0 -1
- package/dist/detector.js +0 -385
- package/dist/detector.js.map +0 -1
- package/dist/extractors/python-extractor.d.ts +0 -19
- package/dist/extractors/python-extractor.d.ts.map +0 -1
- package/dist/extractors/python-extractor.js +0 -164
- package/dist/extractors/python-extractor.js.map +0 -1
- package/dist/grouping.d.ts +0 -54
- package/dist/grouping.d.ts.map +0 -1
- package/dist/grouping.js +0 -347
- package/dist/grouping.js.map +0 -1
- package/dist/index-y2uJSngh.d.mts +0 -60
- package/dist/index-y2uJSngh.d.ts +0 -60
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/python-extractor-BGKGX6BK.mjs +0 -131
- package/dist/python-extractor-ELAKYK2W.mjs +0 -140
- package/dist/scoring-entry.d.mts +0 -23
- package/dist/scoring-entry.d.ts +0 -23
- package/dist/scoring-entry.mjs +0 -6
- package/dist/scoring.d.ts +0 -12
- package/dist/scoring.d.ts.map +0 -1
- package/dist/scoring.js +0 -116
- package/dist/scoring.js.map +0 -1
- package/dist/types-C4lmb2Yh.d.mts +0 -36
- package/dist/types-C4lmb2Yh.d.ts +0 -36
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import {
|
|
2
|
+
calculateSeverity
|
|
3
|
+
} from "./chunk-TIBF7KST.mjs";
|
|
4
|
+
|
|
5
|
+
// src/detector.ts
|
|
6
|
+
import {
|
|
7
|
+
calculateStringSimilarity,
|
|
8
|
+
calculateHeuristicConfidence,
|
|
9
|
+
extractCodeBlocks
|
|
10
|
+
} from "@aiready/core";
|
|
11
|
+
|
|
12
|
+
// src/core/normalizer.ts
|
|
13
|
+
function normalizeCode(code, isPython = false) {
|
|
14
|
+
if (!code) return "";
|
|
15
|
+
let normalized = code;
|
|
16
|
+
if (isPython) {
|
|
17
|
+
normalized = normalized.replace(/#.*/g, "");
|
|
18
|
+
} else {
|
|
19
|
+
normalized = normalized.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
|
|
20
|
+
}
|
|
21
|
+
return normalized.replace(/"[^"]*"/g, '"STR"').replace(/'[^']*'/g, "'STR'").replace(/`[^`]*`/g, "`STR`").replace(/\b\d+\b/g, "NUM").replace(/\s+/g, " ").trim().toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// src/detector.ts
|
|
25
|
+
function extractBlocks(file, content) {
|
|
26
|
+
return extractCodeBlocks(file, content);
|
|
27
|
+
}
|
|
28
|
+
function calculateSimilarity(a, b) {
|
|
29
|
+
return calculateStringSimilarity(a, b);
|
|
30
|
+
}
|
|
31
|
+
function calculateConfidence(similarity, tokens, lines) {
|
|
32
|
+
return calculateHeuristicConfidence(similarity, tokens, lines);
|
|
33
|
+
}
|
|
34
|
+
async function detectDuplicatePatterns(fileContents, options) {
|
|
35
|
+
const {
|
|
36
|
+
minSimilarity,
|
|
37
|
+
minLines,
|
|
38
|
+
streamResults,
|
|
39
|
+
onProgress,
|
|
40
|
+
excludePatterns = [],
|
|
41
|
+
confidenceThreshold = 0,
|
|
42
|
+
ignoreWhitelist = []
|
|
43
|
+
} = options;
|
|
44
|
+
const allBlocks = [];
|
|
45
|
+
const excludeRegexes = excludePatterns.map((p) => new RegExp(p, "i"));
|
|
46
|
+
for (const { file, content } of fileContents) {
|
|
47
|
+
const blocks = extractBlocks(file, content);
|
|
48
|
+
for (const b of blocks) {
|
|
49
|
+
if (b.endLine - b.startLine + 1 < minLines) continue;
|
|
50
|
+
const isExcluded = excludeRegexes.some((regex) => regex.test(b.code));
|
|
51
|
+
if (isExcluded) continue;
|
|
52
|
+
allBlocks.push(b);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
const duplicates = [];
|
|
56
|
+
const totalBlocks = allBlocks.length;
|
|
57
|
+
let comparisons = 0;
|
|
58
|
+
const totalComparisons = totalBlocks * (totalBlocks - 1) / 2;
|
|
59
|
+
if (onProgress) {
|
|
60
|
+
onProgress(
|
|
61
|
+
0,
|
|
62
|
+
totalComparisons,
|
|
63
|
+
`Starting duplicate detection on ${totalBlocks} blocks...`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
for (let i = 0; i < allBlocks.length; i++) {
|
|
67
|
+
if (i % 50 === 0 && i > 0) {
|
|
68
|
+
await new Promise((resolve) => setImmediate(resolve));
|
|
69
|
+
if (onProgress) {
|
|
70
|
+
onProgress(
|
|
71
|
+
comparisons,
|
|
72
|
+
totalComparisons,
|
|
73
|
+
`Analyzing blocks (${i}/${totalBlocks})...`
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const b1 = allBlocks[i];
|
|
78
|
+
const isPython1 = b1.file.toLowerCase().endsWith(".py");
|
|
79
|
+
const norm1 = normalizeCode(b1.code, isPython1);
|
|
80
|
+
for (let j = i + 1; j < allBlocks.length; j++) {
|
|
81
|
+
comparisons++;
|
|
82
|
+
const b2 = allBlocks[j];
|
|
83
|
+
if (b1.file === b2.file) continue;
|
|
84
|
+
const isWhitelisted = ignoreWhitelist.some((pattern) => {
|
|
85
|
+
return b1.file.includes(pattern) && b2.file.includes(pattern) || pattern === `${b1.file}::${b2.file}` || pattern === `${b2.file}::${b1.file}`;
|
|
86
|
+
});
|
|
87
|
+
if (isWhitelisted) continue;
|
|
88
|
+
const isPython2 = b2.file.toLowerCase().endsWith(".py");
|
|
89
|
+
const norm2 = normalizeCode(b2.code, isPython2);
|
|
90
|
+
const sim = calculateSimilarity(norm1, norm2);
|
|
91
|
+
if (sim >= minSimilarity) {
|
|
92
|
+
const confidence = calculateConfidence(
|
|
93
|
+
sim,
|
|
94
|
+
b1.tokens,
|
|
95
|
+
b1.endLine - b1.startLine + 1
|
|
96
|
+
);
|
|
97
|
+
if (confidence < confidenceThreshold) continue;
|
|
98
|
+
const { severity, reason, suggestion, matchedRule } = calculateSeverity(
|
|
99
|
+
b1.file,
|
|
100
|
+
b2.file,
|
|
101
|
+
b1.code,
|
|
102
|
+
sim,
|
|
103
|
+
b1.endLine - b1.startLine + 1
|
|
104
|
+
);
|
|
105
|
+
const dup = {
|
|
106
|
+
file1: b1.file,
|
|
107
|
+
line1: b1.startLine,
|
|
108
|
+
endLine1: b1.endLine,
|
|
109
|
+
file2: b2.file,
|
|
110
|
+
line2: b2.startLine,
|
|
111
|
+
endLine2: b2.endLine,
|
|
112
|
+
code1: b1.code,
|
|
113
|
+
code2: b2.code,
|
|
114
|
+
similarity: sim,
|
|
115
|
+
confidence,
|
|
116
|
+
patternType: b1.patternType,
|
|
117
|
+
tokenCost: b1.tokens + b2.tokens,
|
|
118
|
+
severity,
|
|
119
|
+
reason,
|
|
120
|
+
suggestion,
|
|
121
|
+
matchedRule
|
|
122
|
+
};
|
|
123
|
+
duplicates.push(dup);
|
|
124
|
+
if (streamResults)
|
|
125
|
+
console.log(
|
|
126
|
+
`[DUPLICATE] ${dup.file1}:${dup.line1} <-> ${dup.file2}:${dup.line2} (${Math.round(sim * 100)}%, conf: ${Math.round(confidence * 100)}%)`
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
if (onProgress) {
|
|
132
|
+
onProgress(
|
|
133
|
+
totalComparisons,
|
|
134
|
+
totalComparisons,
|
|
135
|
+
`Duplicate detection complete. Found ${duplicates.length} patterns.`
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
return duplicates.sort((a, b) => b.similarity - a.similarity);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export {
|
|
142
|
+
detectDuplicatePatterns
|
|
143
|
+
};
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
// src/scoring.ts
|
|
2
|
+
import {
|
|
3
|
+
calculateMonthlyCost,
|
|
4
|
+
calculateProductivityImpact,
|
|
5
|
+
DEFAULT_COST_CONFIG,
|
|
6
|
+
ToolName
|
|
7
|
+
} from "@aiready/core";
|
|
8
|
+
function calculatePatternScore(duplicates, totalFilesAnalyzed, costConfig) {
|
|
9
|
+
const actionableDuplicates = duplicates.filter(
|
|
10
|
+
(d) => d.severity !== "info"
|
|
11
|
+
);
|
|
12
|
+
const totalDuplicates = actionableDuplicates.length;
|
|
13
|
+
const totalTokenCost = actionableDuplicates.reduce((sum, d) => sum + d.tokenCost, 0);
|
|
14
|
+
const highImpactDuplicates = actionableDuplicates.filter(
|
|
15
|
+
(d) => d.tokenCost > 1e3 || d.similarity > 0.7
|
|
16
|
+
).length;
|
|
17
|
+
if (totalFilesAnalyzed === 0) {
|
|
18
|
+
return {
|
|
19
|
+
toolName: ToolName.PatternDetect,
|
|
20
|
+
score: 100,
|
|
21
|
+
rawMetrics: {
|
|
22
|
+
totalDuplicates: 0,
|
|
23
|
+
totalTokenCost: 0,
|
|
24
|
+
highImpactDuplicates: 0,
|
|
25
|
+
totalFilesAnalyzed: 0
|
|
26
|
+
},
|
|
27
|
+
factors: [],
|
|
28
|
+
recommendations: []
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
const duplicatesPerFile = totalDuplicates / totalFilesAnalyzed * 100;
|
|
32
|
+
const tokenWastePerFile = totalTokenCost / totalFilesAnalyzed;
|
|
33
|
+
const duplicatesPenalty = Math.min(60, duplicatesPerFile * 0.6);
|
|
34
|
+
const tokenPenalty = Math.min(40, tokenWastePerFile / 125);
|
|
35
|
+
const highImpactPenalty = highImpactDuplicates > 0 ? Math.min(15, highImpactDuplicates * 2 - 5) : -5;
|
|
36
|
+
const score = 100 - duplicatesPenalty - tokenPenalty - highImpactPenalty;
|
|
37
|
+
const finalScore = Math.max(0, Math.min(100, Math.round(score)));
|
|
38
|
+
const factors = [
|
|
39
|
+
{
|
|
40
|
+
name: "Duplication Density",
|
|
41
|
+
impact: -Math.round(duplicatesPenalty),
|
|
42
|
+
description: `${duplicatesPerFile.toFixed(1)} duplicates per 100 files`
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: "Token Waste",
|
|
46
|
+
impact: -Math.round(tokenPenalty),
|
|
47
|
+
description: `${Math.round(tokenWastePerFile)} tokens wasted per file`
|
|
48
|
+
}
|
|
49
|
+
];
|
|
50
|
+
if (highImpactDuplicates > 0) {
|
|
51
|
+
factors.push({
|
|
52
|
+
name: "High-Impact Patterns",
|
|
53
|
+
impact: -Math.round(highImpactPenalty),
|
|
54
|
+
description: `${highImpactDuplicates} high-impact duplicates (>1000 tokens or >70% similar)`
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
factors.push({
|
|
58
|
+
name: "No High-Impact Patterns",
|
|
59
|
+
impact: 5,
|
|
60
|
+
description: "No severe duplicates detected"
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
const recommendations = [];
|
|
64
|
+
if (highImpactDuplicates > 0) {
|
|
65
|
+
const estimatedImpact = Math.min(15, highImpactDuplicates * 3);
|
|
66
|
+
recommendations.push({
|
|
67
|
+
action: `Deduplicate ${highImpactDuplicates} high-impact pattern${highImpactDuplicates > 1 ? "s" : ""}`,
|
|
68
|
+
estimatedImpact,
|
|
69
|
+
priority: "high"
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
if (totalDuplicates > 10 && duplicatesPerFile > 20) {
|
|
73
|
+
const estimatedImpact = Math.min(10, Math.round(duplicatesPenalty * 0.3));
|
|
74
|
+
recommendations.push({
|
|
75
|
+
action: "Extract common patterns into shared utilities",
|
|
76
|
+
estimatedImpact,
|
|
77
|
+
priority: "medium"
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
if (tokenWastePerFile > 2e3) {
|
|
81
|
+
const estimatedImpact = Math.min(8, Math.round(tokenPenalty * 0.4));
|
|
82
|
+
recommendations.push({
|
|
83
|
+
action: "Consolidate duplicated logic to reduce AI context waste",
|
|
84
|
+
estimatedImpact,
|
|
85
|
+
priority: totalTokenCost > 1e4 ? "high" : "medium"
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
const cfg = { ...DEFAULT_COST_CONFIG, ...costConfig };
|
|
89
|
+
const estimatedMonthlyCost = calculateMonthlyCost(totalTokenCost, cfg);
|
|
90
|
+
const issues = duplicates.map((d) => ({
|
|
91
|
+
severity: d.severity === "critical" ? "critical" : d.severity === "major" ? "major" : "minor"
|
|
92
|
+
}));
|
|
93
|
+
const productivityImpact = calculateProductivityImpact(issues);
|
|
94
|
+
return {
|
|
95
|
+
toolName: "pattern-detect",
|
|
96
|
+
score: finalScore,
|
|
97
|
+
rawMetrics: {
|
|
98
|
+
totalDuplicates,
|
|
99
|
+
totalTokenCost,
|
|
100
|
+
highImpactDuplicates,
|
|
101
|
+
totalFilesAnalyzed,
|
|
102
|
+
duplicatesPerFile: Math.round(duplicatesPerFile * 10) / 10,
|
|
103
|
+
tokenWastePerFile: Math.round(tokenWastePerFile),
|
|
104
|
+
// Business value metrics
|
|
105
|
+
estimatedMonthlyCost,
|
|
106
|
+
estimatedDeveloperHours: productivityImpact.totalHours
|
|
107
|
+
},
|
|
108
|
+
factors,
|
|
109
|
+
recommendations
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export {
|
|
114
|
+
calculatePatternScore
|
|
115
|
+
};
|