@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.
Files changed (190) hide show
  1. package/dist/analyzer-entry/index.d.mts +1 -1
  2. package/dist/analyzer-entry/index.d.ts +1 -1
  3. package/dist/analyzer-entry/index.js +370 -135
  4. package/dist/analyzer-entry/index.mjs +4 -3
  5. package/dist/chunk-2P7BQHGR.mjs +306 -0
  6. package/dist/{chunk-VGMM3L3O.mjs → chunk-3EORD7DC.mjs} +1 -1
  7. package/dist/{chunk-GREN7X5H.mjs → chunk-4PVPQMRT.mjs} +2 -2
  8. package/dist/{chunk-RS73WLNI.mjs → chunk-6VDL7TAS.mjs} +5 -113
  9. package/dist/chunk-AQIP4JGM.mjs +283 -0
  10. package/dist/{chunk-JBUZ6YHE.mjs → chunk-B4NLWKPZ.mjs} +85 -9
  11. package/dist/chunk-IPBGVPUX.mjs +143 -0
  12. package/dist/chunk-LUUJOUK5.mjs +283 -0
  13. package/dist/chunk-P3BOCGVV.mjs +498 -0
  14. package/dist/{scoring-entry.js → chunk-PHJE6A3J.mjs} +20 -37
  15. package/dist/chunk-PQXOORR4.mjs +234 -0
  16. package/dist/{chunk-GLKAGFKX.mjs → chunk-RDR75DVI.mjs} +85 -9
  17. package/dist/chunk-SXVLRPMF.mjs +143 -0
  18. package/dist/{chunk-DNZS4ESD.mjs → chunk-SY7RX5YQ.mjs} +85 -9
  19. package/dist/{context-rules-entry.js → chunk-TIBF7KST.mjs} +81 -78
  20. package/dist/chunk-WYYSQX5M.mjs +467 -0
  21. package/dist/{chunk-I6ETJC7L.mjs → chunk-X553BOMI.mjs} +56 -26
  22. package/dist/{chunk-K7BO57OO.mjs → chunk-Y6OB7K34.mjs} +80 -4
  23. package/dist/chunk-YLVV6YZ5.mjs +143 -0
  24. package/dist/chunk-ZUWPFVJV.mjs +115 -0
  25. package/dist/chunk-ZZMONVPE.mjs +467 -0
  26. package/dist/cli.js +402 -167
  27. package/dist/cli.mjs +4 -3
  28. package/dist/context-rules-entry/index.d.mts +35 -1
  29. package/dist/context-rules-entry/index.d.ts +35 -1
  30. package/dist/context-rules-entry/index.js +194 -48
  31. package/dist/context-rules-entry/index.mjs +1 -1
  32. package/dist/detector-entry/index.js +192 -46
  33. package/dist/detector-entry/index.mjs +2 -2
  34. package/dist/{analyzer-entry-BVz-HnZd.d.mts → index-B-pnXpgn.d.mts} +10 -1
  35. package/dist/{index-BwuoiCNm.d.ts → index-CWgYOKaK.d.ts} +35 -16
  36. package/dist/{index-BVz-HnZd.d.mts → index-Dl4BrGIT.d.mts} +35 -16
  37. package/dist/{analyzer-entry-BwuoiCNm.d.ts → index-DqS2e0kK.d.ts} +10 -1
  38. package/dist/index.d.mts +5 -6
  39. package/dist/index.d.ts +5 -6
  40. package/dist/index.js +467 -214
  41. package/dist/index.mjs +37 -22
  42. package/dist/scoring-entry/index.js +7 -3
  43. package/dist/scoring-entry/index.mjs +1 -1
  44. package/package.json +2 -2
  45. package/dist/analyzer-entry.d.mts +0 -100
  46. package/dist/analyzer-entry.d.ts +0 -100
  47. package/dist/analyzer-entry.js +0 -693
  48. package/dist/analyzer-entry.mjs +0 -12
  49. package/dist/chunk-262N2JB7.mjs +0 -497
  50. package/dist/chunk-2R7HOR5H.mjs +0 -777
  51. package/dist/chunk-3D7RVGHM.mjs +0 -64
  52. package/dist/chunk-3LS3E6MO.mjs +0 -508
  53. package/dist/chunk-3VRQYFW3.mjs +0 -782
  54. package/dist/chunk-3WK24ZOX.mjs +0 -860
  55. package/dist/chunk-3YYN6ZXN.mjs +0 -1038
  56. package/dist/chunk-4BPRGZRG.mjs +0 -1041
  57. package/dist/chunk-4UHDGB7U.mjs +0 -920
  58. package/dist/chunk-5LYDB7DY.mjs +0 -771
  59. package/dist/chunk-65G3HXLQ.mjs +0 -497
  60. package/dist/chunk-65UQ5J2J.mjs +0 -64
  61. package/dist/chunk-6JTVOBJX.mjs +0 -64
  62. package/dist/chunk-6OEHUI5J.mjs +0 -1045
  63. package/dist/chunk-6YUGU4P4.mjs +0 -914
  64. package/dist/chunk-7EJGNGXM.mjs +0 -771
  65. package/dist/chunk-7O2DUBSN.mjs +0 -1058
  66. package/dist/chunk-7S4AUL5S.mjs +0 -911
  67. package/dist/chunk-A76JUWER.mjs +0 -786
  68. package/dist/chunk-AJZUNNFH.mjs +0 -817
  69. package/dist/chunk-AXHGYYYZ.mjs +0 -404
  70. package/dist/chunk-BKRPSTT2.mjs +0 -64
  71. package/dist/chunk-BUBQ3W6W.mjs +0 -980
  72. package/dist/chunk-CCHM2VLK.mjs +0 -1051
  73. package/dist/chunk-CHFK6EBT.mjs +0 -419
  74. package/dist/chunk-CMT3MWWO.mjs +0 -948
  75. package/dist/chunk-CMWW24HW.mjs +0 -259
  76. package/dist/chunk-CTDBJP25.mjs +0 -1043
  77. package/dist/chunk-DGAKXYIP.mjs +0 -1041
  78. package/dist/chunk-DQSLTL7J.mjs +0 -788
  79. package/dist/chunk-DR5W7S3Z.mjs +0 -968
  80. package/dist/chunk-EFUKPMBE.mjs +0 -950
  81. package/dist/chunk-EVBFDILL.mjs +0 -927
  82. package/dist/chunk-EXORBAXR.mjs +0 -887
  83. package/dist/chunk-EZT3NZGB.mjs +0 -1057
  84. package/dist/chunk-FWUKMJEQ.mjs +0 -1133
  85. package/dist/chunk-GSJFORRO.mjs +0 -504
  86. package/dist/chunk-H4ADJYOG.mjs +0 -925
  87. package/dist/chunk-H5FB2USZ.mjs +0 -762
  88. package/dist/chunk-H73HEG7M.mjs +0 -670
  89. package/dist/chunk-HOS5Z2NC.mjs +0 -669
  90. package/dist/chunk-HXHQOQB5.mjs +0 -508
  91. package/dist/chunk-INEOYHUM.mjs +0 -911
  92. package/dist/chunk-INJ4SBTV.mjs +0 -754
  93. package/dist/chunk-J5CW6NYY.mjs +0 -64
  94. package/dist/chunk-JAFZCZAP.mjs +0 -776
  95. package/dist/chunk-JKVKOXYR.mjs +0 -407
  96. package/dist/chunk-JTHW7EYW.mjs +0 -1041
  97. package/dist/chunk-JWR3AHKO.mjs +0 -788
  98. package/dist/chunk-KC2CQMG2.mjs +0 -858
  99. package/dist/chunk-KDWGWBP5.mjs +0 -832
  100. package/dist/chunk-KPEK5REL.mjs +0 -919
  101. package/dist/chunk-KT6O2IAE.mjs +0 -861
  102. package/dist/chunk-KWMNN3TG.mjs +0 -391
  103. package/dist/chunk-LUA5FXSZ.mjs +0 -771
  104. package/dist/chunk-LYKRYBSM.mjs +0 -64
  105. package/dist/chunk-M4PQMW34.mjs +0 -480
  106. package/dist/chunk-MH6LBXZF.mjs +0 -816
  107. package/dist/chunk-MHU3CL4R.mjs +0 -64
  108. package/dist/chunk-MJWBS6SM.mjs +0 -1058
  109. package/dist/chunk-OFGMDX66.mjs +0 -402
  110. package/dist/chunk-P7B6Z4I2.mjs +0 -1043
  111. package/dist/chunk-PBCXSG7E.mjs +0 -658
  112. package/dist/chunk-PEEHSFDR.mjs +0 -1058
  113. package/dist/chunk-PSVG2NLH.mjs +0 -966
  114. package/dist/chunk-PWNQ6JZW.mjs +0 -508
  115. package/dist/chunk-QE4E3F7C.mjs +0 -410
  116. package/dist/chunk-QEP76HGK.mjs +0 -1039
  117. package/dist/chunk-QX2BQJEO.mjs +0 -1058
  118. package/dist/chunk-R2S73CVG.mjs +0 -503
  119. package/dist/chunk-RMGDSNLE.mjs +0 -770
  120. package/dist/chunk-S2KQFII2.mjs +0 -491
  121. package/dist/chunk-SLDK5PQK.mjs +0 -1129
  122. package/dist/chunk-SNSDVGWW.mjs +0 -783
  123. package/dist/chunk-SUUZMLPS.mjs +0 -391
  124. package/dist/chunk-SVCSIZ2A.mjs +0 -259
  125. package/dist/chunk-T2C6WS73.mjs +0 -670
  126. package/dist/chunk-TCG2G32F.mjs +0 -911
  127. package/dist/chunk-TGBZP7SB.mjs +0 -773
  128. package/dist/chunk-THF4RW63.mjs +0 -254
  129. package/dist/chunk-TJKDLVLN.mjs +0 -503
  130. package/dist/chunk-TXWPOVYU.mjs +0 -402
  131. package/dist/chunk-UB3CGOQ7.mjs +0 -64
  132. package/dist/chunk-UKIKN27B.mjs +0 -950
  133. package/dist/chunk-V5DP4FP6.mjs +0 -876
  134. package/dist/chunk-VRMXVYDZ.mjs +0 -419
  135. package/dist/chunk-WACZ5LFH.mjs +0 -1055
  136. package/dist/chunk-WC7CBAA7.mjs +0 -1058
  137. package/dist/chunk-WKBCNITM.mjs +0 -1072
  138. package/dist/chunk-WMOGJFME.mjs +0 -391
  139. package/dist/chunk-X4GR2N2M.mjs +0 -947
  140. package/dist/chunk-XCWY2DQY.mjs +0 -788
  141. package/dist/chunk-XJD35DS6.mjs +0 -1058
  142. package/dist/chunk-XNPID6FU.mjs +0 -391
  143. package/dist/chunk-XUUVS54V.mjs +0 -776
  144. package/dist/chunk-YCGV65F5.mjs +0 -508
  145. package/dist/chunk-YJYDBFT3.mjs +0 -780
  146. package/dist/chunk-YP3HEDQW.mjs +0 -859
  147. package/dist/chunk-YSDOUNJJ.mjs +0 -1142
  148. package/dist/chunk-Z6GBFFOV.mjs +0 -1040
  149. package/dist/cli.d.ts.map +0 -1
  150. package/dist/cli.js.map +0 -1
  151. package/dist/context-rules-entry-y2uJSngh.d.mts +0 -60
  152. package/dist/context-rules-entry-y2uJSngh.d.ts +0 -60
  153. package/dist/context-rules-entry.d.mts +0 -55
  154. package/dist/context-rules-entry.d.ts +0 -55
  155. package/dist/context-rules-entry.mjs +0 -12
  156. package/dist/context-rules.d.ts +0 -41
  157. package/dist/context-rules.d.ts.map +0 -1
  158. package/dist/context-rules.js +0 -225
  159. package/dist/context-rules.js.map +0 -1
  160. package/dist/detector-entry.d.mts +0 -14
  161. package/dist/detector-entry.d.ts +0 -14
  162. package/dist/detector-entry.js +0 -301
  163. package/dist/detector-entry.mjs +0 -7
  164. package/dist/detector.d.ts +0 -40
  165. package/dist/detector.d.ts.map +0 -1
  166. package/dist/detector.js +0 -385
  167. package/dist/detector.js.map +0 -1
  168. package/dist/extractors/python-extractor.d.ts +0 -19
  169. package/dist/extractors/python-extractor.d.ts.map +0 -1
  170. package/dist/extractors/python-extractor.js +0 -164
  171. package/dist/extractors/python-extractor.js.map +0 -1
  172. package/dist/grouping.d.ts +0 -54
  173. package/dist/grouping.d.ts.map +0 -1
  174. package/dist/grouping.js +0 -347
  175. package/dist/grouping.js.map +0 -1
  176. package/dist/index-y2uJSngh.d.mts +0 -60
  177. package/dist/index-y2uJSngh.d.ts +0 -60
  178. package/dist/index.d.ts.map +0 -1
  179. package/dist/index.js.map +0 -1
  180. package/dist/python-extractor-BGKGX6BK.mjs +0 -131
  181. package/dist/python-extractor-ELAKYK2W.mjs +0 -140
  182. package/dist/scoring-entry.d.mts +0 -23
  183. package/dist/scoring-entry.d.ts +0 -23
  184. package/dist/scoring-entry.mjs +0 -6
  185. package/dist/scoring.d.ts +0 -12
  186. package/dist/scoring.d.ts.map +0 -1
  187. package/dist/scoring.js +0 -116
  188. package/dist/scoring.js.map +0 -1
  189. package/dist/types-C4lmb2Yh.d.mts +0 -36
  190. package/dist/types-C4lmb2Yh.d.ts +0 -36
@@ -1,301 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/detector-entry.ts
21
- var detector_entry_exports = {};
22
- __export(detector_entry_exports, {
23
- detectDuplicatePatterns: () => detectDuplicatePatterns
24
- });
25
- module.exports = __toCommonJS(detector_entry_exports);
26
-
27
- // src/detector.ts
28
- var import_core2 = require("@aiready/core");
29
-
30
- // src/context-rules.ts
31
- var import_core = require("@aiready/core");
32
- var CONTEXT_RULES = [
33
- // Test Fixtures - Intentional duplication for test isolation
34
- {
35
- name: "test-fixtures",
36
- detect: (file, code) => {
37
- const isTestFile = file.includes(".test.") || file.includes(".spec.") || file.includes("__tests__") || file.includes("/test/") || file.includes("/tests/");
38
- const hasTestFixtures = code.includes("beforeAll") || code.includes("afterAll") || code.includes("beforeEach") || code.includes("afterEach") || code.includes("setUp") || code.includes("tearDown");
39
- return isTestFile && hasTestFixtures;
40
- },
41
- severity: import_core.Severity.Info,
42
- reason: "Test fixture duplication is intentional for test isolation",
43
- suggestion: "Consider if shared test setup would improve maintainability without coupling tests"
44
- },
45
- // Email/Document Templates - Often intentionally similar for consistency
46
- {
47
- name: "templates",
48
- detect: (file, code) => {
49
- const isTemplate = file.includes("/templates/") || file.includes("-template") || file.includes("/email-templates/") || file.includes("/emails/");
50
- const hasTemplateContent = (code.includes("return") || code.includes("export")) && (code.includes("html") || code.includes("subject") || code.includes("body"));
51
- return isTemplate && hasTemplateContent;
52
- },
53
- severity: import_core.Severity.Minor,
54
- reason: "Template duplication may be intentional for maintainability and branding consistency",
55
- suggestion: "Extract shared structure only if templates become hard to maintain"
56
- },
57
- // E2E/Integration Test Page Objects - Test independence
58
- {
59
- name: "e2e-page-objects",
60
- detect: (file, code) => {
61
- const isE2ETest = file.includes("e2e/") || file.includes("/e2e/") || file.includes(".e2e.") || file.includes("/playwright/") || file.includes("playwright/") || file.includes("/cypress/") || file.includes("cypress/") || file.includes("/integration/") || file.includes("integration/");
62
- const hasPageObjectPatterns = code.includes("page.") || code.includes("await page") || code.includes("locator") || code.includes("getBy") || code.includes("selector") || code.includes("click(") || code.includes("fill(");
63
- return isE2ETest && hasPageObjectPatterns;
64
- },
65
- severity: import_core.Severity.Minor,
66
- reason: "E2E test duplication ensures test independence and reduces coupling",
67
- suggestion: "Consider page object pattern only if duplication causes maintenance issues"
68
- },
69
- // Configuration Files - Often necessarily similar by design
70
- {
71
- name: "config-files",
72
- detect: (file) => {
73
- return file.endsWith(".config.ts") || file.endsWith(".config.js") || file.includes("jest.config") || file.includes("vite.config") || file.includes("webpack.config") || file.includes("rollup.config") || file.includes("tsconfig");
74
- },
75
- severity: import_core.Severity.Minor,
76
- reason: "Configuration files often have similar structure by design",
77
- suggestion: "Consider shared config base only if configurations become hard to maintain"
78
- },
79
- // Type Definitions - Duplication for type safety and module independence
80
- {
81
- name: "type-definitions",
82
- detect: (file, code) => {
83
- const isTypeFile = file.endsWith(".d.ts") || file.includes("/types/");
84
- const hasTypeDefinitions = code.includes("interface ") || code.includes("type ") || code.includes("enum ");
85
- return isTypeFile && hasTypeDefinitions;
86
- },
87
- severity: import_core.Severity.Info,
88
- reason: "Type duplication may be intentional for module independence and type safety",
89
- suggestion: "Extract to shared types package only if causing maintenance burden"
90
- },
91
- // Migration Scripts - One-off scripts that are similar by nature
92
- {
93
- name: "migration-scripts",
94
- detect: (file) => {
95
- return file.includes("/migrations/") || file.includes("/migrate/") || file.includes(".migration.");
96
- },
97
- severity: import_core.Severity.Info,
98
- reason: "Migration scripts are typically one-off and intentionally similar",
99
- suggestion: "Duplication is acceptable for migration scripts"
100
- },
101
- // Mock Data - Test data intentionally duplicated
102
- {
103
- name: "mock-data",
104
- detect: (file, code) => {
105
- const isMockFile = file.includes("/mocks/") || file.includes("/__mocks__/") || file.includes("/fixtures/") || file.includes(".mock.") || file.includes(".fixture.");
106
- const hasMockData = code.includes("mock") || code.includes("Mock") || code.includes("fixture") || code.includes("stub") || code.includes("export const");
107
- return isMockFile && hasMockData;
108
- },
109
- severity: import_core.Severity.Info,
110
- reason: "Mock data duplication is expected for comprehensive test coverage",
111
- suggestion: "Consider shared factories only for complex mock generation"
112
- },
113
- // Tool Implementations - Structural Boilerplate
114
- {
115
- name: "tool-implementations",
116
- detect: (file, code) => {
117
- const isToolFile = file.includes("/tools/") || file.endsWith(".tool.ts") || code.includes("toolDefinitions");
118
- const hasToolStructure = code.includes("execute") && (code.includes("try") || code.includes("catch"));
119
- return isToolFile && hasToolStructure;
120
- },
121
- severity: import_core.Severity.Info,
122
- reason: "Tool implementations share structural boilerplate but have distinct business logic",
123
- suggestion: "Tool duplication is acceptable for boilerplate interface wrappers"
124
- }
125
- ];
126
- function calculateSeverity(file1, file2, code, similarity, linesOfCode) {
127
- for (const rule of CONTEXT_RULES) {
128
- if (rule.detect(file1, code) || rule.detect(file2, code)) {
129
- return {
130
- severity: rule.severity,
131
- reason: rule.reason,
132
- suggestion: rule.suggestion,
133
- matchedRule: rule.name
134
- };
135
- }
136
- }
137
- if (similarity >= 0.95 && linesOfCode >= 30) {
138
- return {
139
- severity: import_core.Severity.Critical,
140
- reason: "Large nearly-identical code blocks waste tokens and create maintenance burden",
141
- suggestion: "Extract to shared utility module immediately"
142
- };
143
- } else if (similarity >= 0.95 && linesOfCode >= 15) {
144
- return {
145
- severity: import_core.Severity.Major,
146
- reason: "Nearly identical code should be consolidated",
147
- suggestion: "Move to shared utility file"
148
- };
149
- } else if (similarity >= 0.85) {
150
- return {
151
- severity: import_core.Severity.Major,
152
- reason: "High similarity indicates significant duplication",
153
- suggestion: "Extract common logic to shared function"
154
- };
155
- } else if (similarity >= 0.7) {
156
- return {
157
- severity: import_core.Severity.Minor,
158
- reason: "Moderate similarity detected",
159
- suggestion: "Consider extracting shared patterns if code evolves together"
160
- };
161
- } else {
162
- return {
163
- severity: import_core.Severity.Minor,
164
- reason: "Minor similarity detected",
165
- suggestion: "Monitor but refactoring may not be worthwhile"
166
- };
167
- }
168
- }
169
-
170
- // src/core/normalizer.ts
171
- function normalizeCode(code, isPython = false) {
172
- if (!code) return "";
173
- let normalized = code;
174
- if (isPython) {
175
- normalized = normalized.replace(/#.*/g, "");
176
- } else {
177
- normalized = normalized.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "");
178
- }
179
- return normalized.replace(/"[^"]*"/g, '"STR"').replace(/'[^']*'/g, "'STR'").replace(/`[^`]*`/g, "`STR`").replace(/\b\d+\b/g, "NUM").replace(/\s+/g, " ").trim().toLowerCase();
180
- }
181
-
182
- // src/detector.ts
183
- function extractBlocks(file, content) {
184
- return (0, import_core2.extractCodeBlocks)(file, content);
185
- }
186
- function calculateSimilarity(a, b) {
187
- return (0, import_core2.calculateStringSimilarity)(a, b);
188
- }
189
- function calculateConfidence(similarity, tokens, lines) {
190
- return (0, import_core2.calculateHeuristicConfidence)(similarity, tokens, lines);
191
- }
192
- async function detectDuplicatePatterns(fileContents, options) {
193
- const {
194
- minSimilarity,
195
- minLines,
196
- streamResults,
197
- onProgress,
198
- excludePatterns = [],
199
- confidenceThreshold = 0,
200
- ignoreWhitelist = []
201
- } = options;
202
- const allBlocks = [];
203
- const excludeRegexes = excludePatterns.map((p) => new RegExp(p, "i"));
204
- for (const { file, content } of fileContents) {
205
- const blocks = extractBlocks(file, content);
206
- for (const b of blocks) {
207
- if (b.endLine - b.startLine + 1 < minLines) continue;
208
- const isExcluded = excludeRegexes.some((regex) => regex.test(b.code));
209
- if (isExcluded) continue;
210
- allBlocks.push(b);
211
- }
212
- }
213
- const duplicates = [];
214
- const totalBlocks = allBlocks.length;
215
- let comparisons = 0;
216
- const totalComparisons = totalBlocks * (totalBlocks - 1) / 2;
217
- if (onProgress) {
218
- onProgress(
219
- 0,
220
- totalComparisons,
221
- `Starting duplicate detection on ${totalBlocks} blocks...`
222
- );
223
- }
224
- for (let i = 0; i < allBlocks.length; i++) {
225
- if (i % 50 === 0 && i > 0) {
226
- await new Promise((resolve) => setImmediate(resolve));
227
- if (onProgress) {
228
- onProgress(
229
- comparisons,
230
- totalComparisons,
231
- `Analyzing blocks (${i}/${totalBlocks})...`
232
- );
233
- }
234
- }
235
- const b1 = allBlocks[i];
236
- const isPython1 = b1.file.toLowerCase().endsWith(".py");
237
- const norm1 = normalizeCode(b1.code, isPython1);
238
- for (let j = i + 1; j < allBlocks.length; j++) {
239
- comparisons++;
240
- const b2 = allBlocks[j];
241
- if (b1.file === b2.file) continue;
242
- const isWhitelisted = ignoreWhitelist.some((pattern) => {
243
- return b1.file.includes(pattern) && b2.file.includes(pattern) || pattern === `${b1.file}::${b2.file}` || pattern === `${b2.file}::${b1.file}`;
244
- });
245
- if (isWhitelisted) continue;
246
- const isPython2 = b2.file.toLowerCase().endsWith(".py");
247
- const norm2 = normalizeCode(b2.code, isPython2);
248
- const sim = calculateSimilarity(norm1, norm2);
249
- if (sim >= minSimilarity) {
250
- const confidence = calculateConfidence(
251
- sim,
252
- b1.tokens,
253
- b1.endLine - b1.startLine + 1
254
- );
255
- if (confidence < confidenceThreshold) continue;
256
- const { severity, reason, suggestion, matchedRule } = calculateSeverity(
257
- b1.file,
258
- b2.file,
259
- b1.code,
260
- sim,
261
- b1.endLine - b1.startLine + 1
262
- );
263
- const dup = {
264
- file1: b1.file,
265
- line1: b1.startLine,
266
- endLine1: b1.endLine,
267
- file2: b2.file,
268
- line2: b2.startLine,
269
- endLine2: b2.endLine,
270
- code1: b1.code,
271
- code2: b2.code,
272
- similarity: sim,
273
- confidence,
274
- patternType: b1.patternType,
275
- tokenCost: b1.tokens + b2.tokens,
276
- severity,
277
- reason,
278
- suggestion,
279
- matchedRule
280
- };
281
- duplicates.push(dup);
282
- if (streamResults)
283
- console.log(
284
- `[DUPLICATE] ${dup.file1}:${dup.line1} <-> ${dup.file2}:${dup.line2} (${Math.round(sim * 100)}%, conf: ${Math.round(confidence * 100)}%)`
285
- );
286
- }
287
- }
288
- }
289
- if (onProgress) {
290
- onProgress(
291
- totalComparisons,
292
- totalComparisons,
293
- `Duplicate detection complete. Found ${duplicates.length} patterns.`
294
- );
295
- }
296
- return duplicates.sort((a, b) => b.similarity - a.similarity);
297
- }
298
- // Annotate the CommonJS export names for ESM import in node:
299
- 0 && (module.exports = {
300
- detectDuplicatePatterns
301
- });
@@ -1,7 +0,0 @@
1
- import {
2
- detectDuplicatePatterns
3
- } from "./chunk-VGMM3L3O.mjs";
4
- import "./chunk-I6ETJC7L.mjs";
5
- export {
6
- detectDuplicatePatterns
7
- };
@@ -1,40 +0,0 @@
1
- import { type Severity } from './context-rules';
2
- export interface DuplicatePattern {
3
- file1: string;
4
- file2: string;
5
- line1: number;
6
- line2: number;
7
- endLine1: number;
8
- endLine2: number;
9
- similarity: number;
10
- snippet: string;
11
- patternType: PatternType;
12
- tokenCost: number;
13
- linesOfCode: number;
14
- severity: Severity;
15
- reason?: string;
16
- suggestion?: string;
17
- matchedRule?: string;
18
- }
19
- export type PatternType = 'function' | 'class-method' | 'api-handler' | 'validator' | 'utility' | 'component' | 'unknown';
20
- interface FileContent {
21
- file: string;
22
- content: string;
23
- }
24
- interface DetectionOptions {
25
- minSimilarity: number;
26
- minLines: number;
27
- maxBlocks?: number;
28
- batchSize?: number;
29
- approx?: boolean;
30
- minSharedTokens?: number;
31
- maxCandidatesPerBlock?: number;
32
- maxComparisons?: number;
33
- streamResults?: boolean;
34
- }
35
- /**
36
- * Detect duplicate patterns across files with enhanced analysis
37
- */
38
- export declare function detectDuplicatePatterns(files: FileContent[], options: DetectionOptions): Promise<DuplicatePattern[]>;
39
- export {};
40
- //# sourceMappingURL=detector.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"detector.d.ts","sourceRoot":"","sources":["../src/detector.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAEnE,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,MAAM,WAAW,GACnB,UAAU,GACV,cAAc,GACd,aAAa,GACb,WAAW,GACX,SAAS,GACT,WAAW,GACX,SAAS,CAAC;AAEd,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,gBAAgB;IACxB,aAAa,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAyMD;;GAEG;AACH,wBAAsB,uBAAuB,CAC3C,KAAK,EAAE,WAAW,EAAE,EACpB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,gBAAgB,EAAE,CAAC,CA6R7B"}