@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
@@ -0,0 +1,283 @@
1
+ // src/context-rules.ts
2
+ import {
3
+ IssueType,
4
+ getSeverityLabel,
5
+ filterBySeverity,
6
+ Severity
7
+ } from "@aiready/core";
8
+ var CONTEXT_RULES = [
9
+ // Test Fixtures - Intentional duplication for test isolation
10
+ {
11
+ name: "test-fixtures",
12
+ detect: (file, code) => {
13
+ const isTestFile = file.includes(".test.") || file.includes(".spec.") || file.includes("__tests__") || file.includes("/test/") || file.includes("/tests/");
14
+ const hasTestFixtures = code.includes("beforeAll") || code.includes("afterAll") || code.includes("beforeEach") || code.includes("afterEach") || code.includes("setUp") || code.includes("tearDown");
15
+ return isTestFile && hasTestFixtures;
16
+ },
17
+ severity: Severity.Info,
18
+ reason: "Test fixture duplication is intentional for test isolation",
19
+ suggestion: "Consider if shared test setup would improve maintainability without coupling tests"
20
+ },
21
+ // Email/Document Templates - Often intentionally similar for consistency
22
+ {
23
+ name: "templates",
24
+ detect: (file, code) => {
25
+ const isTemplate = file.includes("/templates/") || file.includes("-template") || file.includes("/email-templates/") || file.includes("/emails/");
26
+ const hasTemplateContent = (code.includes("return") || code.includes("export")) && (code.includes("html") || code.includes("subject") || code.includes("body"));
27
+ return isTemplate && hasTemplateContent;
28
+ },
29
+ severity: Severity.Info,
30
+ reason: "Template duplication may be intentional for maintainability and branding consistency",
31
+ suggestion: "Extract shared structure only if templates become hard to maintain"
32
+ },
33
+ // E2E/Integration Test Page Objects - Test independence
34
+ {
35
+ name: "e2e-page-objects",
36
+ detect: (file, code) => {
37
+ 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/");
38
+ const hasPageObjectPatterns = code.includes("page.") || code.includes("await page") || code.includes("locator") || code.includes("getBy") || code.includes("selector") || code.includes("click(") || code.includes("fill(");
39
+ return isE2ETest && hasPageObjectPatterns;
40
+ },
41
+ severity: Severity.Info,
42
+ reason: "E2E test duplication ensures test independence and reduces coupling",
43
+ suggestion: "Consider page object pattern only if duplication causes maintenance issues"
44
+ },
45
+ // Configuration Files - Often necessarily similar by design
46
+ {
47
+ name: "config-files",
48
+ detect: (file) => {
49
+ 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");
50
+ },
51
+ severity: Severity.Info,
52
+ reason: "Configuration files often have similar structure by design",
53
+ suggestion: "Consider shared config base only if configurations become hard to maintain"
54
+ },
55
+ // Type Definitions - Duplication for type safety and module independence
56
+ // Matches type-only files OR interface/type definitions in component files
57
+ {
58
+ name: "type-definitions",
59
+ detect: (file, code) => {
60
+ const isTypeFile = file.endsWith(".d.ts") || file.includes("/types/");
61
+ const hasOnlyTypeDefinitions = (code.includes("interface ") || code.includes("type ") || code.includes("enum ")) && !code.includes("function ") && !code.includes("class ") && !code.includes("const ") && !code.includes("let ") && !code.includes("export default");
62
+ const isInterfaceOnlySnippet = code.trim().startsWith("interface ") && code.includes("{") && code.includes("}") && !code.includes("function ") && !code.includes("const ") && !code.includes("return ");
63
+ return isTypeFile && hasOnlyTypeDefinitions || isInterfaceOnlySnippet;
64
+ },
65
+ severity: Severity.Info,
66
+ reason: "Type/interface definitions are intentionally duplicated for module independence",
67
+ suggestion: "Extract to shared types package only if causing maintenance burden"
68
+ },
69
+ // Migration Scripts - One-off scripts that are similar by nature
70
+ {
71
+ name: "migration-scripts",
72
+ detect: (file) => {
73
+ return file.includes("/migrations/") || file.includes("/migrate/") || file.includes(".migration.");
74
+ },
75
+ severity: Severity.Info,
76
+ reason: "Migration scripts are typically one-off and intentionally similar",
77
+ suggestion: "Duplication is acceptable for migration scripts"
78
+ },
79
+ // Mock Data - Test data intentionally duplicated
80
+ {
81
+ name: "mock-data",
82
+ detect: (file, code) => {
83
+ const isMockFile = file.includes("/mocks/") || file.includes("/__mocks__/") || file.includes("/fixtures/") || file.includes(".mock.") || file.includes(".fixture.");
84
+ const hasMockData = code.includes("mock") || code.includes("Mock") || code.includes("fixture") || code.includes("stub") || code.includes("export const");
85
+ return isMockFile && hasMockData;
86
+ },
87
+ severity: Severity.Info,
88
+ reason: "Mock data duplication is expected for comprehensive test coverage",
89
+ suggestion: "Consider shared factories only for complex mock generation"
90
+ },
91
+ // Tool Implementations - Structural Boilerplate
92
+ {
93
+ name: "tool-implementations",
94
+ detect: (file, code) => {
95
+ const isToolFile = file.includes("/tools/") || file.endsWith(".tool.ts") || code.includes("toolDefinitions");
96
+ const hasToolStructure = code.includes("execute") && (code.includes("try") || code.includes("catch"));
97
+ return isToolFile && hasToolStructure;
98
+ },
99
+ severity: Severity.Info,
100
+ reason: "Tool implementations share structural boilerplate but have distinct business logic",
101
+ suggestion: "Tool duplication is acceptable for boilerplate interface wrappers"
102
+ },
103
+ // Common UI Event Handlers - Very specific patterns only
104
+ {
105
+ name: "common-ui-handlers",
106
+ detect: (file, code) => {
107
+ const isUIFile = file.includes("/components/") || file.includes(".tsx") || file.includes(".jsx") || file.includes("/hooks/");
108
+ const hasCommonHandler = code.includes("handleClickOutside") && code.includes("dropdownRef.current") && code.includes("!dropdownRef.current.contains") || code.includes("handleEscape") && code.includes("event.key") && code.includes("=== 'Escape'") || code.includes("handleClickInside") && code.includes("event.stopPropagation");
109
+ return isUIFile && hasCommonHandler;
110
+ },
111
+ severity: Severity.Info,
112
+ reason: "Common UI event handlers are boilerplate patterns that repeat across components",
113
+ suggestion: "Consider extracting to shared hooks (useClickOutside, useEscapeKey) only if causing maintenance issues"
114
+ },
115
+ // Utility Functions - Small helpers in dedicated utility files
116
+ {
117
+ name: "utility-functions",
118
+ detect: (file, code) => {
119
+ const isUtilFile = file.endsWith(".util.ts") || file.endsWith(".helper.ts") || file.endsWith(".utils.ts");
120
+ const hasUtilPattern = code.includes("function format") || code.includes("function parse") || code.includes("function sanitize") || code.includes("function normalize") || code.includes("function convert");
121
+ return isUtilFile && hasUtilPattern;
122
+ },
123
+ severity: Severity.Info,
124
+ reason: "Utility functions in dedicated utility files may be intentionally similar",
125
+ suggestion: "Consider extracting to shared utilities only if causing significant duplication"
126
+ },
127
+ // React/Vue Hooks - Standard patterns
128
+ {
129
+ name: "shared-hooks",
130
+ detect: (file, code) => {
131
+ const isHookFile = file.includes("/hooks/") || file.endsWith(".hook.ts") || file.endsWith(".hook.tsx");
132
+ const hasHookPattern = code.includes("function use") || code.includes("export function use") || code.includes("const use") || code.includes("export const use");
133
+ return isHookFile && hasHookPattern;
134
+ },
135
+ severity: Severity.Info,
136
+ reason: "Hooks follow standard patterns and are often intentionally similar across components",
137
+ suggestion: "Consider extracting common hook logic only if hooks become complex"
138
+ },
139
+ // CLI Command Definitions - Commander.js boilerplate patterns
140
+ {
141
+ name: "cli-command-definitions",
142
+ detect: (file, code) => {
143
+ const isCliFile = file.includes("/commands/") || file.includes("/cli/") || file.endsWith(".command.ts");
144
+ const hasCommandPattern = (code.includes(".command(") || code.includes("defineCommand")) && (code.includes(".description(") || code.includes(".option(")) && (code.includes(".action(") || code.includes("async"));
145
+ return isCliFile && hasCommandPattern;
146
+ },
147
+ severity: Severity.Info,
148
+ reason: "CLI command definitions follow standard Commander.js patterns and are intentionally similar",
149
+ suggestion: "Command boilerplate duplication is acceptable for CLI interfaces"
150
+ },
151
+ // Score/Rating Helper Functions - Common threshold patterns
152
+ {
153
+ name: "score-helpers",
154
+ detect: (file, code) => {
155
+ const isHelperFile = file.includes("/utils/") || file.includes("/helpers/") || file.endsWith(".util.ts");
156
+ const hasScorePattern = (code.includes("if (score >=") || code.includes("if (score >")) && (code.includes("return") && code.includes("'")) && code.split("if (score").length >= 3;
157
+ return isHelperFile && hasScorePattern;
158
+ },
159
+ severity: Severity.Info,
160
+ reason: "Score/rating helper functions use common threshold patterns that are intentionally similar",
161
+ suggestion: "Score formatting duplication is acceptable for consistent UI display"
162
+ },
163
+ // D3/Canvas Event Handlers - Standard visualization patterns
164
+ {
165
+ name: "visualization-handlers",
166
+ detect: (file, code) => {
167
+ const isVizFile = file.includes("/visualizer/") || file.includes("/charts/") || file.includes("GraphCanvas") || file.includes("ForceDirected");
168
+ const hasVizPattern = (code.includes("dragstarted") || code.includes("dragged") || code.includes("dragended")) && (code.includes("simulation") || code.includes("d3.") || code.includes("alphaTarget"));
169
+ return isVizFile && hasVizPattern;
170
+ },
171
+ severity: Severity.Info,
172
+ reason: "D3/visualization event handlers follow standard patterns and are intentionally similar",
173
+ suggestion: "Visualization boilerplate duplication is acceptable for interactive charts"
174
+ },
175
+ // Icon/Switch Statement Helpers - Common enum-to-value patterns
176
+ {
177
+ name: "switch-helpers",
178
+ detect: (file, code) => {
179
+ const hasSwitchPattern = code.includes("switch (") && code.includes("case '") && code.includes("return") && code.split("case ").length >= 4;
180
+ const hasIconPattern = code.includes("getIcon") || code.includes("getColor") || code.includes("getLabel") || code.includes("getRating");
181
+ return hasSwitchPattern && hasIconPattern;
182
+ },
183
+ severity: Severity.Info,
184
+ reason: "Switch statement helpers for enum-to-value mapping are inherently similar",
185
+ suggestion: "Switch duplication is acceptable for mapping enums to display values"
186
+ },
187
+ // Common API/Utility Functions - Legitimate duplication across modules
188
+ {
189
+ name: "common-api-functions",
190
+ detect: (file, code) => {
191
+ const isApiFile = file.includes("/api/") || file.includes("/lib/") || file.includes("/utils/") || file.endsWith(".ts");
192
+ const hasCommonApiPattern = code.includes("getStripe") && code.includes("process.env.STRIPE_SECRET_KEY") || code.includes("getUserByEmail") && code.includes("queryItems") || code.includes("updateUser") && code.includes("buildUpdateExpression") || code.includes("listUserRepositories") && code.includes("queryItems") || code.includes("listTeamRepositories") && code.includes("queryItems") || code.includes("getRemediation") && code.includes("queryItems") || code.includes("formatBreakdownKey") && code.includes(".replace(/([A-Z])/g") || code.includes("queryItems") && code.includes("KeyConditionExpression") || code.includes("putItem") && code.includes("createdAt") || code.includes("updateItem") && code.includes("buildUpdateExpression");
193
+ return isApiFile && hasCommonApiPattern;
194
+ },
195
+ severity: Severity.Info,
196
+ reason: "Common API/utility functions are legitimately duplicated across modules for clarity and independence",
197
+ suggestion: "Consider extracting to shared utilities only if causing significant duplication"
198
+ },
199
+ // Next.js Route Handler Patterns - Boilerplate API route patterns
200
+ {
201
+ name: "nextjs-route-handlers",
202
+ detect: (file, code) => {
203
+ const isRouteFile = file.includes("/api/") && (file.endsWith("/route.ts") || file.endsWith("/route.js"));
204
+ const hasRoutePattern = code.includes("export async function POST") || code.includes("export async function GET") || code.includes("export async function PUT") || code.includes("export async function DELETE") || code.includes("NextResponse.json") || code.includes("NextRequest");
205
+ return isRouteFile && hasRoutePattern;
206
+ },
207
+ severity: Severity.Info,
208
+ reason: "Next.js route handlers follow standard patterns and are intentionally similar across endpoints",
209
+ suggestion: "Route handler duplication is acceptable for API endpoint boilerplate"
210
+ },
211
+ // Validation Functions - Inherently similar patterns
212
+ {
213
+ name: "validation-functions",
214
+ detect: (file, code) => {
215
+ const hasValidationPattern = code.includes("isValid") || code.includes("validate") || code.includes("checkValid") || code.includes("isEmail") || code.includes("isPhone") || code.includes("isUrl") || code.includes("isNumeric") || code.includes("isAlpha") || code.includes("isAlphanumeric") || code.includes("isEmpty") || code.includes("isNotEmpty") || code.includes("isRequired") || code.includes("isOptional");
216
+ return hasValidationPattern;
217
+ },
218
+ severity: Severity.Info,
219
+ reason: "Validation functions are inherently similar and often intentionally duplicated for domain clarity",
220
+ suggestion: "Consider extracting to shared validators only if validation logic becomes complex"
221
+ }
222
+ ];
223
+ function calculateSeverity(file1, file2, code, similarity, linesOfCode) {
224
+ for (const rule of CONTEXT_RULES) {
225
+ if (rule.detect(file1, code) || rule.detect(file2, code)) {
226
+ return {
227
+ severity: rule.severity,
228
+ reason: rule.reason,
229
+ suggestion: rule.suggestion,
230
+ matchedRule: rule.name
231
+ };
232
+ }
233
+ }
234
+ if (similarity >= 0.95 && linesOfCode >= 30) {
235
+ return {
236
+ severity: Severity.Critical,
237
+ reason: "Large nearly-identical code blocks waste tokens and create maintenance burden",
238
+ suggestion: "Extract to shared utility module immediately"
239
+ };
240
+ } else if (similarity >= 0.95 && linesOfCode >= 15) {
241
+ return {
242
+ severity: Severity.Major,
243
+ reason: "Nearly identical code should be consolidated",
244
+ suggestion: "Move to shared utility file"
245
+ };
246
+ } else if (similarity >= 0.85) {
247
+ return {
248
+ severity: Severity.Major,
249
+ reason: "High similarity indicates significant duplication",
250
+ suggestion: "Extract common logic to shared function"
251
+ };
252
+ } else if (similarity >= 0.7) {
253
+ return {
254
+ severity: Severity.Minor,
255
+ reason: "Moderate similarity detected",
256
+ suggestion: "Consider extracting shared patterns if code evolves together"
257
+ };
258
+ } else {
259
+ return {
260
+ severity: Severity.Minor,
261
+ reason: "Minor similarity detected",
262
+ suggestion: "Monitor but refactoring may not be worthwhile"
263
+ };
264
+ }
265
+ }
266
+ function getSeverityThreshold(severity) {
267
+ const thresholds = {
268
+ [Severity.Critical]: 0.95,
269
+ [Severity.Major]: 0.85,
270
+ [Severity.Minor]: 0.5,
271
+ [Severity.Info]: 0
272
+ };
273
+ return thresholds[severity] || 0;
274
+ }
275
+
276
+ export {
277
+ IssueType,
278
+ getSeverityLabel,
279
+ filterBySeverity,
280
+ CONTEXT_RULES,
281
+ calculateSeverity,
282
+ getSeverityThreshold
283
+ };
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  detectDuplicatePatterns
3
- } from "./chunk-RS73WLNI.mjs";
3
+ } from "./chunk-SXVLRPMF.mjs";
4
4
  import {
5
5
  calculateSeverity
6
- } from "./chunk-I6ETJC7L.mjs";
6
+ } from "./chunk-LUUJOUK5.mjs";
7
7
 
8
8
  // src/grouping.ts
9
- import { getSeverityLevel } from "@aiready/core";
9
+ import { Severity, getSeverityLevel } from "@aiready/core";
10
10
  import path from "path";
11
11
  function groupDuplicatesByFilePair(duplicates) {
12
12
  const groups = /* @__PURE__ */ new Map();
@@ -124,9 +124,77 @@ function filterClustersByImpact(clusters, minTokenCost = 1e3, minFiles = 3) {
124
124
  (c) => c.totalTokenCost >= minTokenCost && c.files.length >= minFiles
125
125
  );
126
126
  }
127
+ function isPureInterfaceDefinition(code) {
128
+ const trimmed = code.trim();
129
+ if (!trimmed.startsWith("interface ") && !trimmed.startsWith("type ") && !trimmed.startsWith("export interface ") && !trimmed.startsWith("export type ") && !trimmed.startsWith("enum ") && !trimmed.startsWith("export enum ")) {
130
+ return false;
131
+ }
132
+ if (trimmed.includes("={") || trimmed.includes("=> {") || trimmed.includes("function ") || trimmed.includes("() {") || trimmed.includes(" implements ")) {
133
+ return false;
134
+ }
135
+ if (trimmed.length > 200) return false;
136
+ return true;
137
+ }
138
+ var BRAND_INDICATORS = [
139
+ "cyberpunk",
140
+ "cyber-blue",
141
+ "cyber-purple",
142
+ "slate-900",
143
+ "slate-400",
144
+ "zinc-",
145
+ "indigo-",
146
+ "neon-",
147
+ "glassmorphism",
148
+ "backdrop-blur"
149
+ ];
150
+ function isBrandSpecificComponent(filePath) {
151
+ const lower = filePath.toLowerCase();
152
+ const brandingTerms = ["landing", "clawmore", "platform", "apps/"];
153
+ for (const term of brandingTerms) {
154
+ if (lower.includes(term)) return true;
155
+ }
156
+ return false;
157
+ }
158
+ function areBrandSpecificVariants(file1, file2, code1, code2) {
159
+ const f1IsBrand = isBrandSpecificComponent(file1);
160
+ const f2IsBrand = isBrandSpecificComponent(file2);
161
+ if (f1IsBrand && f2IsBrand && file1 !== file2) {
162
+ const hasBrandKeyword = (code) => {
163
+ const lowerCode = code.toLowerCase();
164
+ return BRAND_INDICATORS.some((ind) => lowerCode.includes(ind));
165
+ };
166
+ const code1Brand = hasBrandKeyword(code1);
167
+ const code2Brand = hasBrandKeyword(code2);
168
+ if (code1Brand && code2Brand) {
169
+ return true;
170
+ }
171
+ }
172
+ return false;
173
+ }
174
+ function filterBrandSpecificVariants(duplicates) {
175
+ return duplicates.filter((dup) => {
176
+ if (dup.file1 === dup.file2) return true;
177
+ const isBrandVariant = areBrandSpecificVariants(
178
+ dup.file1,
179
+ dup.file2,
180
+ dup.code1,
181
+ dup.code2
182
+ );
183
+ if (isBrandVariant) {
184
+ dup.severity = Severity.Info;
185
+ dup.suggestion = "Brand-specific themed component variant (intentional)";
186
+ }
187
+ const isInterfaceDef = isPureInterfaceDefinition(dup.code1) && isPureInterfaceDefinition(dup.code2);
188
+ if (isInterfaceDef) {
189
+ dup.severity = Severity.Info;
190
+ dup.suggestion = "Pure interface/type definition - intentional for module independence";
191
+ }
192
+ return true;
193
+ });
194
+ }
127
195
 
128
196
  // src/analyzer.ts
129
- import { scanFiles, readFileContent, Severity as Severity2, IssueType } from "@aiready/core";
197
+ import { scanFiles, readFileContent, Severity as Severity2, IssueType as IssueType2 } from "@aiready/core";
130
198
  function getRefactoringSuggestion(patternType, similarity) {
131
199
  const baseMessages = {
132
200
  "api-handler": "Extract common middleware or create a base handler class",
@@ -167,7 +235,7 @@ async function getSmartDefaults(directory, userOptions) {
167
235
  6,
168
236
  Math.min(20, 6 + Math.floor(estimatedBlocks / 1e3) * 2)
169
237
  );
170
- const minSimilarity = Math.min(0.85, 0.5 + estimatedBlocks / 5e3 * 0.3);
238
+ const minSimilarity = Math.min(0.75, 0.45 + estimatedBlocks / 1e4 * 0.3);
171
239
  const batchSize = estimatedBlocks > 1e3 ? 200 : 100;
172
240
  const severity = estimatedBlocks > 3e3 ? "high" : "all";
173
241
  const maxCandidatesPerBlock = Math.max(
@@ -268,15 +336,21 @@ async function analyzePatterns(options) {
268
336
  ignoreWhitelist,
269
337
  onProgress: options.onProgress
270
338
  });
339
+ filterBrandSpecificVariants(duplicates);
271
340
  for (const file of files) {
272
341
  const fileDuplicates = duplicates.filter(
273
342
  (dup) => dup.file1 === file || dup.file2 === file
274
343
  );
275
344
  const issues = fileDuplicates.map((dup) => {
276
345
  const otherFile = dup.file1 === file ? dup.file2 : dup.file1;
277
- const severity2 = dup.similarity > 0.95 ? Severity2.Critical : dup.similarity > 0.9 ? Severity2.Major : Severity2.Minor;
346
+ let severity2;
347
+ if (dup.severity === "info" || dup.severity === "Info") {
348
+ severity2 = Severity2.Info;
349
+ } else {
350
+ severity2 = dup.similarity > 0.95 ? Severity2.Critical : dup.similarity > 0.9 ? Severity2.Major : Severity2.Minor;
351
+ }
278
352
  return {
279
- type: IssueType.DuplicatePattern,
353
+ type: IssueType2.DuplicatePattern,
280
354
  severity: severity2,
281
355
  message: `${dup.patternType} pattern ${Math.round(dup.similarity * 100)}% similar to ${otherFile} (${dup.tokenCost} tokens wasted)`,
282
356
  location: {
@@ -327,9 +401,9 @@ async function analyzePatterns(options) {
327
401
  return { results, duplicates, files, groups, clusters, config: finalOptions };
328
402
  }
329
403
  function generateSummary(results) {
330
- const allIssues = results.flatMap((r) => r.issues);
404
+ const allIssues = results.flatMap((r) => r.issues || []);
331
405
  const totalTokenCost = results.reduce(
332
- (sum, r) => sum + (r.metrics.tokenCost || 0),
406
+ (sum, r) => sum + (r.metrics?.tokenCost || 0),
333
407
  0
334
408
  );
335
409
  const patternsByType = {
@@ -385,6 +459,8 @@ export {
385
459
  groupDuplicatesByFilePair,
386
460
  createRefactorClusters,
387
461
  filterClustersByImpact,
462
+ areBrandSpecificVariants,
463
+ filterBrandSpecificVariants,
388
464
  getSmartDefaults,
389
465
  analyzePatterns,
390
466
  generateSummary
@@ -0,0 +1,143 @@
1
+ import {
2
+ calculateSeverity
3
+ } from "./chunk-2P7BQHGR.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
+ };