@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,234 @@
|
|
|
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.Minor,
|
|
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.Minor,
|
|
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.Minor,
|
|
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
|
+
// Only apply to .d.ts files or files in /types/ directories, not to all files containing interfaces
|
|
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
|
+
return isTypeFile && hasOnlyTypeDefinitions;
|
|
63
|
+
},
|
|
64
|
+
severity: Severity.Info,
|
|
65
|
+
reason: "Type-only files may be intentionally duplicated for module independence",
|
|
66
|
+
suggestion: "Extract to shared types package only if causing maintenance burden"
|
|
67
|
+
},
|
|
68
|
+
// Migration Scripts - One-off scripts that are similar by nature
|
|
69
|
+
{
|
|
70
|
+
name: "migration-scripts",
|
|
71
|
+
detect: (file) => {
|
|
72
|
+
return file.includes("/migrations/") || file.includes("/migrate/") || file.includes(".migration.");
|
|
73
|
+
},
|
|
74
|
+
severity: Severity.Info,
|
|
75
|
+
reason: "Migration scripts are typically one-off and intentionally similar",
|
|
76
|
+
suggestion: "Duplication is acceptable for migration scripts"
|
|
77
|
+
},
|
|
78
|
+
// Mock Data - Test data intentionally duplicated
|
|
79
|
+
{
|
|
80
|
+
name: "mock-data",
|
|
81
|
+
detect: (file, code) => {
|
|
82
|
+
const isMockFile = file.includes("/mocks/") || file.includes("/__mocks__/") || file.includes("/fixtures/") || file.includes(".mock.") || file.includes(".fixture.");
|
|
83
|
+
const hasMockData = code.includes("mock") || code.includes("Mock") || code.includes("fixture") || code.includes("stub") || code.includes("export const");
|
|
84
|
+
return isMockFile && hasMockData;
|
|
85
|
+
},
|
|
86
|
+
severity: Severity.Info,
|
|
87
|
+
reason: "Mock data duplication is expected for comprehensive test coverage",
|
|
88
|
+
suggestion: "Consider shared factories only for complex mock generation"
|
|
89
|
+
},
|
|
90
|
+
// Tool Implementations - Structural Boilerplate
|
|
91
|
+
{
|
|
92
|
+
name: "tool-implementations",
|
|
93
|
+
detect: (file, code) => {
|
|
94
|
+
const isToolFile = file.includes("/tools/") || file.endsWith(".tool.ts") || code.includes("toolDefinitions");
|
|
95
|
+
const hasToolStructure = code.includes("execute") && (code.includes("try") || code.includes("catch"));
|
|
96
|
+
return isToolFile && hasToolStructure;
|
|
97
|
+
},
|
|
98
|
+
severity: Severity.Info,
|
|
99
|
+
reason: "Tool implementations share structural boilerplate but have distinct business logic",
|
|
100
|
+
suggestion: "Tool duplication is acceptable for boilerplate interface wrappers"
|
|
101
|
+
},
|
|
102
|
+
// Common UI Event Handlers - Very specific patterns only
|
|
103
|
+
{
|
|
104
|
+
name: "common-ui-handlers",
|
|
105
|
+
detect: (file, code) => {
|
|
106
|
+
const isUIFile = file.includes("/components/") || file.includes(".tsx") || file.includes(".jsx") || file.includes("/hooks/");
|
|
107
|
+
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");
|
|
108
|
+
return isUIFile && hasCommonHandler;
|
|
109
|
+
},
|
|
110
|
+
severity: Severity.Info,
|
|
111
|
+
reason: "Common UI event handlers are boilerplate patterns that repeat across components",
|
|
112
|
+
suggestion: "Consider extracting to shared hooks (useClickOutside, useEscapeKey) only if causing maintenance issues"
|
|
113
|
+
},
|
|
114
|
+
// Utility Functions - Small helpers in dedicated utility files
|
|
115
|
+
{
|
|
116
|
+
name: "utility-functions",
|
|
117
|
+
detect: (file, code) => {
|
|
118
|
+
const isUtilFile = file.endsWith(".util.ts") || file.endsWith(".helper.ts") || file.endsWith(".utils.ts");
|
|
119
|
+
const hasUtilPattern = code.includes("function format") || code.includes("function parse") || code.includes("function sanitize") || code.includes("function normalize") || code.includes("function convert");
|
|
120
|
+
return isUtilFile && hasUtilPattern;
|
|
121
|
+
},
|
|
122
|
+
severity: Severity.Minor,
|
|
123
|
+
reason: "Utility functions in dedicated utility files may be intentionally similar",
|
|
124
|
+
suggestion: "Consider extracting to shared utilities only if causing significant duplication"
|
|
125
|
+
},
|
|
126
|
+
// React/Vue Hooks - Standard patterns
|
|
127
|
+
{
|
|
128
|
+
name: "shared-hooks",
|
|
129
|
+
detect: (file, code) => {
|
|
130
|
+
const isHookFile = file.includes("/hooks/") || file.endsWith(".hook.ts") || file.endsWith(".hook.tsx");
|
|
131
|
+
const hasHookPattern = code.includes("function use") || code.includes("export function use") || code.includes("const use") || code.includes("export const use");
|
|
132
|
+
return isHookFile && hasHookPattern;
|
|
133
|
+
},
|
|
134
|
+
severity: Severity.Info,
|
|
135
|
+
reason: "Hooks follow standard patterns and are often intentionally similar across components",
|
|
136
|
+
suggestion: "Consider extracting common hook logic only if hooks become complex"
|
|
137
|
+
},
|
|
138
|
+
// Common API/Utility Functions - Legitimate duplication across modules
|
|
139
|
+
{
|
|
140
|
+
name: "common-api-functions",
|
|
141
|
+
detect: (file, code) => {
|
|
142
|
+
const isApiFile = file.includes("/api/") || file.includes("/lib/") || file.includes("/utils/") || file.endsWith(".ts");
|
|
143
|
+
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");
|
|
144
|
+
return isApiFile && hasCommonApiPattern;
|
|
145
|
+
},
|
|
146
|
+
severity: Severity.Info,
|
|
147
|
+
reason: "Common API/utility functions are legitimately duplicated across modules for clarity and independence",
|
|
148
|
+
suggestion: "Consider extracting to shared utilities only if causing significant duplication"
|
|
149
|
+
},
|
|
150
|
+
// Next.js Route Handler Patterns - Boilerplate API route patterns
|
|
151
|
+
{
|
|
152
|
+
name: "nextjs-route-handlers",
|
|
153
|
+
detect: (file, code) => {
|
|
154
|
+
const isRouteFile = file.includes("/api/") && (file.endsWith("/route.ts") || file.endsWith("/route.js"));
|
|
155
|
+
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");
|
|
156
|
+
return isRouteFile && hasRoutePattern;
|
|
157
|
+
},
|
|
158
|
+
severity: Severity.Info,
|
|
159
|
+
reason: "Next.js route handlers follow standard patterns and are intentionally similar across endpoints",
|
|
160
|
+
suggestion: "Route handler duplication is acceptable for API endpoint boilerplate"
|
|
161
|
+
},
|
|
162
|
+
// Validation Functions - Inherently similar patterns
|
|
163
|
+
{
|
|
164
|
+
name: "validation-functions",
|
|
165
|
+
detect: (file, code) => {
|
|
166
|
+
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");
|
|
167
|
+
return hasValidationPattern;
|
|
168
|
+
},
|
|
169
|
+
severity: Severity.Minor,
|
|
170
|
+
reason: "Validation functions are inherently similar and often intentionally duplicated for domain clarity",
|
|
171
|
+
suggestion: "Consider extracting to shared validators only if validation logic becomes complex"
|
|
172
|
+
}
|
|
173
|
+
];
|
|
174
|
+
function calculateSeverity(file1, file2, code, similarity, linesOfCode) {
|
|
175
|
+
for (const rule of CONTEXT_RULES) {
|
|
176
|
+
if (rule.detect(file1, code) || rule.detect(file2, code)) {
|
|
177
|
+
return {
|
|
178
|
+
severity: rule.severity,
|
|
179
|
+
reason: rule.reason,
|
|
180
|
+
suggestion: rule.suggestion,
|
|
181
|
+
matchedRule: rule.name
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
if (similarity >= 0.95 && linesOfCode >= 30) {
|
|
186
|
+
return {
|
|
187
|
+
severity: Severity.Critical,
|
|
188
|
+
reason: "Large nearly-identical code blocks waste tokens and create maintenance burden",
|
|
189
|
+
suggestion: "Extract to shared utility module immediately"
|
|
190
|
+
};
|
|
191
|
+
} else if (similarity >= 0.95 && linesOfCode >= 15) {
|
|
192
|
+
return {
|
|
193
|
+
severity: Severity.Major,
|
|
194
|
+
reason: "Nearly identical code should be consolidated",
|
|
195
|
+
suggestion: "Move to shared utility file"
|
|
196
|
+
};
|
|
197
|
+
} else if (similarity >= 0.85) {
|
|
198
|
+
return {
|
|
199
|
+
severity: Severity.Major,
|
|
200
|
+
reason: "High similarity indicates significant duplication",
|
|
201
|
+
suggestion: "Extract common logic to shared function"
|
|
202
|
+
};
|
|
203
|
+
} else if (similarity >= 0.7) {
|
|
204
|
+
return {
|
|
205
|
+
severity: Severity.Minor,
|
|
206
|
+
reason: "Moderate similarity detected",
|
|
207
|
+
suggestion: "Consider extracting shared patterns if code evolves together"
|
|
208
|
+
};
|
|
209
|
+
} else {
|
|
210
|
+
return {
|
|
211
|
+
severity: Severity.Minor,
|
|
212
|
+
reason: "Minor similarity detected",
|
|
213
|
+
suggestion: "Monitor but refactoring may not be worthwhile"
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
function getSeverityThreshold(severity) {
|
|
218
|
+
const thresholds = {
|
|
219
|
+
[Severity.Critical]: 0.95,
|
|
220
|
+
[Severity.Major]: 0.85,
|
|
221
|
+
[Severity.Minor]: 0.5,
|
|
222
|
+
[Severity.Info]: 0
|
|
223
|
+
};
|
|
224
|
+
return thresholds[severity] || 0;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export {
|
|
228
|
+
IssueType,
|
|
229
|
+
getSeverityLabel,
|
|
230
|
+
filterBySeverity,
|
|
231
|
+
CONTEXT_RULES,
|
|
232
|
+
calculateSeverity,
|
|
233
|
+
getSeverityThreshold
|
|
234
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
detectDuplicatePatterns
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3EORD7DC.mjs";
|
|
4
4
|
import {
|
|
5
5
|
calculateSeverity
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-AQIP4JGM.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.
|
|
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
|
-
|
|
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:
|
|
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
|
|
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-LUUJOUK5.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
|
+
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
detectDuplicatePatterns
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YLVV6YZ5.mjs";
|
|
4
4
|
import {
|
|
5
5
|
calculateSeverity
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-TIBF7KST.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.
|
|
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
|
-
|
|
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:
|
|
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
|
|
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
|