@aiready/pattern-detect 0.11.4 â 0.11.6
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/__tests__/context-rules.test.d.ts +2 -0
- package/dist/__tests__/context-rules.test.d.ts.map +1 -0
- package/dist/__tests__/context-rules.test.js +189 -0
- package/dist/__tests__/context-rules.test.js.map +1 -0
- package/dist/__tests__/detector.test.d.ts +2 -0
- package/dist/__tests__/detector.test.d.ts.map +1 -0
- package/dist/__tests__/detector.test.js +259 -0
- package/dist/__tests__/detector.test.js.map +1 -0
- package/dist/__tests__/grouping.test.d.ts +2 -0
- package/dist/__tests__/grouping.test.d.ts.map +1 -0
- package/dist/__tests__/grouping.test.js +443 -0
- package/dist/__tests__/grouping.test.js.map +1 -0
- package/dist/__tests__/scoring.test.d.ts +2 -0
- package/dist/__tests__/scoring.test.d.ts.map +1 -0
- package/dist/__tests__/scoring.test.js +102 -0
- package/dist/__tests__/scoring.test.js.map +1 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js.map +1 -0
- package/dist/context-rules.d.ts +41 -0
- package/dist/context-rules.d.ts.map +1 -0
- package/dist/context-rules.js +225 -0
- package/dist/context-rules.js.map +1 -0
- package/dist/detector.d.ts +40 -0
- package/dist/detector.d.ts.map +1 -0
- package/dist/detector.js +385 -0
- package/dist/detector.js.map +1 -0
- package/dist/extractors/python-extractor.d.ts +19 -0
- package/dist/extractors/python-extractor.d.ts.map +1 -0
- package/dist/extractors/python-extractor.js +164 -0
- package/dist/extractors/python-extractor.js.map +1 -0
- package/dist/grouping.d.ts +54 -0
- package/dist/grouping.d.ts.map +1 -0
- package/dist/grouping.js +347 -0
- package/dist/grouping.js.map +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js.map +1 -0
- package/dist/scoring.d.ts +12 -0
- package/dist/scoring.d.ts.map +1 -0
- package/dist/scoring.js +116 -0
- package/dist/scoring.js.map +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context-aware severity detection for duplicate patterns
|
|
3
|
+
* Identifies intentional duplication patterns and adjusts severity accordingly
|
|
4
|
+
*/
|
|
5
|
+
export type Severity = 'critical' | 'major' | 'minor' | 'info';
|
|
6
|
+
export interface ContextRule {
|
|
7
|
+
name: string;
|
|
8
|
+
detect: (file: string, code: string) => boolean;
|
|
9
|
+
severity: Severity;
|
|
10
|
+
reason: string;
|
|
11
|
+
suggestion?: string;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Context rules for detecting intentional or acceptable duplication patterns
|
|
15
|
+
* Rules are checked in order - first match wins
|
|
16
|
+
*/
|
|
17
|
+
export declare const CONTEXT_RULES: ContextRule[];
|
|
18
|
+
/**
|
|
19
|
+
* Calculate severity based on context rules and code characteristics
|
|
20
|
+
*/
|
|
21
|
+
export declare function calculateSeverity(file1: string, file2: string, code: string, similarity: number, linesOfCode: number): {
|
|
22
|
+
severity: Severity;
|
|
23
|
+
reason?: string;
|
|
24
|
+
suggestion?: string;
|
|
25
|
+
matchedRule?: string;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Get a human-readable severity label with emoji
|
|
29
|
+
*/
|
|
30
|
+
export declare function getSeverityLabel(severity: Severity): string;
|
|
31
|
+
/**
|
|
32
|
+
* Filter duplicates by minimum severity threshold
|
|
33
|
+
*/
|
|
34
|
+
export declare function filterBySeverity<T extends {
|
|
35
|
+
severity: Severity;
|
|
36
|
+
}>(duplicates: T[], minSeverity: Severity): T[];
|
|
37
|
+
/**
|
|
38
|
+
* Get severity threshold for filtering
|
|
39
|
+
*/
|
|
40
|
+
export declare function getSeverityThreshold(severity: Severity): number;
|
|
41
|
+
//# sourceMappingURL=context-rules.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-rules.d.ts","sourceRoot":"","sources":["../src/context-rules.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,QAAQ,GAAG,UAAU,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,CAAC;AAE/D,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC;IAChD,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,WAAW,EA4JtC,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,GAClB;IACD,QAAQ,EAAE,QAAQ,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CA6CA;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAQ3D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS;IAAE,QAAQ,EAAE,QAAQ,CAAA;CAAE,EAC/D,UAAU,EAAE,CAAC,EAAE,EACf,WAAW,EAAE,QAAQ,GACpB,CAAC,EAAE,CAUL;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAQ/D"}
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Context-aware severity detection for duplicate patterns
|
|
3
|
+
* Identifies intentional duplication patterns and adjusts severity accordingly
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Context rules for detecting intentional or acceptable duplication patterns
|
|
7
|
+
* Rules are checked in order - first match wins
|
|
8
|
+
*/
|
|
9
|
+
export const CONTEXT_RULES = [
|
|
10
|
+
// Test Fixtures - Intentional duplication for test isolation
|
|
11
|
+
{
|
|
12
|
+
name: 'test-fixtures',
|
|
13
|
+
detect: (file, code) => {
|
|
14
|
+
const isTestFile = file.includes('.test.') ||
|
|
15
|
+
file.includes('.spec.') ||
|
|
16
|
+
file.includes('__tests__') ||
|
|
17
|
+
file.includes('/test/') ||
|
|
18
|
+
file.includes('/tests/');
|
|
19
|
+
const hasTestFixtures = code.includes('beforeAll') ||
|
|
20
|
+
code.includes('afterAll') ||
|
|
21
|
+
code.includes('beforeEach') ||
|
|
22
|
+
code.includes('afterEach') ||
|
|
23
|
+
code.includes('setUp') ||
|
|
24
|
+
code.includes('tearDown');
|
|
25
|
+
return isTestFile && hasTestFixtures;
|
|
26
|
+
},
|
|
27
|
+
severity: 'info',
|
|
28
|
+
reason: 'Test fixture duplication is intentional for test isolation',
|
|
29
|
+
suggestion: 'Consider if shared test setup would improve maintainability without coupling tests',
|
|
30
|
+
},
|
|
31
|
+
// Email/Document Templates - Often intentionally similar for consistency
|
|
32
|
+
{
|
|
33
|
+
name: 'templates',
|
|
34
|
+
detect: (file, code) => {
|
|
35
|
+
const isTemplate = file.includes('/templates/') ||
|
|
36
|
+
file.includes('-template') ||
|
|
37
|
+
file.includes('/email-templates/') ||
|
|
38
|
+
file.includes('/emails/');
|
|
39
|
+
const hasTemplateContent = (code.includes('return') || code.includes('export')) &&
|
|
40
|
+
(code.includes('html') || code.includes('subject') || code.includes('body'));
|
|
41
|
+
return isTemplate && hasTemplateContent;
|
|
42
|
+
},
|
|
43
|
+
severity: 'minor',
|
|
44
|
+
reason: 'Template duplication may be intentional for maintainability and branding consistency',
|
|
45
|
+
suggestion: 'Extract shared structure only if templates become hard to maintain',
|
|
46
|
+
},
|
|
47
|
+
// E2E/Integration Test Page Objects - Test independence
|
|
48
|
+
{
|
|
49
|
+
name: 'e2e-page-objects',
|
|
50
|
+
detect: (file, code) => {
|
|
51
|
+
const isE2ETest = file.includes('e2e/') ||
|
|
52
|
+
file.includes('/e2e/') ||
|
|
53
|
+
file.includes('.e2e.') ||
|
|
54
|
+
file.includes('/playwright/') ||
|
|
55
|
+
file.includes('playwright/') ||
|
|
56
|
+
file.includes('/cypress/') ||
|
|
57
|
+
file.includes('cypress/') ||
|
|
58
|
+
file.includes('/integration/') ||
|
|
59
|
+
file.includes('integration/');
|
|
60
|
+
const hasPageObjectPatterns = code.includes('page.') ||
|
|
61
|
+
code.includes('await page') ||
|
|
62
|
+
code.includes('locator') ||
|
|
63
|
+
code.includes('getBy') ||
|
|
64
|
+
code.includes('selector') ||
|
|
65
|
+
code.includes('click(') ||
|
|
66
|
+
code.includes('fill(');
|
|
67
|
+
return isE2ETest && hasPageObjectPatterns;
|
|
68
|
+
},
|
|
69
|
+
severity: 'minor',
|
|
70
|
+
reason: 'E2E test duplication ensures test independence and reduces coupling',
|
|
71
|
+
suggestion: 'Consider page object pattern only if duplication causes maintenance issues',
|
|
72
|
+
},
|
|
73
|
+
// Configuration Files - Often necessarily similar by design
|
|
74
|
+
{
|
|
75
|
+
name: 'config-files',
|
|
76
|
+
detect: (file) => {
|
|
77
|
+
return (file.endsWith('.config.ts') ||
|
|
78
|
+
file.endsWith('.config.js') ||
|
|
79
|
+
file.includes('jest.config') ||
|
|
80
|
+
file.includes('vite.config') ||
|
|
81
|
+
file.includes('webpack.config') ||
|
|
82
|
+
file.includes('rollup.config') ||
|
|
83
|
+
file.includes('tsconfig'));
|
|
84
|
+
},
|
|
85
|
+
severity: 'minor',
|
|
86
|
+
reason: 'Configuration files often have similar structure by design',
|
|
87
|
+
suggestion: 'Consider shared config base only if configurations become hard to maintain',
|
|
88
|
+
},
|
|
89
|
+
// Type Definitions - Duplication for type safety and module independence
|
|
90
|
+
{
|
|
91
|
+
name: 'type-definitions',
|
|
92
|
+
detect: (file, code) => {
|
|
93
|
+
const isTypeFile = file.endsWith('.d.ts') || file.includes('/types/');
|
|
94
|
+
const hasTypeDefinitions = code.includes('interface ') ||
|
|
95
|
+
code.includes('type ') ||
|
|
96
|
+
code.includes('enum ');
|
|
97
|
+
return isTypeFile && hasTypeDefinitions;
|
|
98
|
+
},
|
|
99
|
+
severity: 'info',
|
|
100
|
+
reason: 'Type duplication may be intentional for module independence and type safety',
|
|
101
|
+
suggestion: 'Extract to shared types package only if causing maintenance burden',
|
|
102
|
+
},
|
|
103
|
+
// Migration Scripts - One-off scripts that are similar by nature
|
|
104
|
+
{
|
|
105
|
+
name: 'migration-scripts',
|
|
106
|
+
detect: (file) => {
|
|
107
|
+
return (file.includes('/migrations/') ||
|
|
108
|
+
file.includes('/migrate/') ||
|
|
109
|
+
file.includes('.migration.'));
|
|
110
|
+
},
|
|
111
|
+
severity: 'info',
|
|
112
|
+
reason: 'Migration scripts are typically one-off and intentionally similar',
|
|
113
|
+
suggestion: 'Duplication is acceptable for migration scripts',
|
|
114
|
+
},
|
|
115
|
+
// Mock Data - Test data intentionally duplicated
|
|
116
|
+
{
|
|
117
|
+
name: 'mock-data',
|
|
118
|
+
detect: (file, code) => {
|
|
119
|
+
const isMockFile = file.includes('/mocks/') ||
|
|
120
|
+
file.includes('/__mocks__/') ||
|
|
121
|
+
file.includes('/fixtures/') ||
|
|
122
|
+
file.includes('.mock.') ||
|
|
123
|
+
file.includes('.fixture.');
|
|
124
|
+
const hasMockData = code.includes('mock') ||
|
|
125
|
+
code.includes('Mock') ||
|
|
126
|
+
code.includes('fixture') ||
|
|
127
|
+
code.includes('stub') ||
|
|
128
|
+
code.includes('export const');
|
|
129
|
+
return isMockFile && hasMockData;
|
|
130
|
+
},
|
|
131
|
+
severity: 'info',
|
|
132
|
+
reason: 'Mock data duplication is expected for comprehensive test coverage',
|
|
133
|
+
suggestion: 'Consider shared factories only for complex mock generation',
|
|
134
|
+
},
|
|
135
|
+
];
|
|
136
|
+
/**
|
|
137
|
+
* Calculate severity based on context rules and code characteristics
|
|
138
|
+
*/
|
|
139
|
+
export function calculateSeverity(file1, file2, code, similarity, linesOfCode) {
|
|
140
|
+
// Check context rules in priority order (first match wins)
|
|
141
|
+
for (const rule of CONTEXT_RULES) {
|
|
142
|
+
if (rule.detect(file1, code) || rule.detect(file2, code)) {
|
|
143
|
+
return {
|
|
144
|
+
severity: rule.severity,
|
|
145
|
+
reason: rule.reason,
|
|
146
|
+
suggestion: rule.suggestion,
|
|
147
|
+
matchedRule: rule.name,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Default severity based on similarity and size for non-contextual duplicates
|
|
152
|
+
if (similarity >= 0.95 && linesOfCode >= 30) {
|
|
153
|
+
return {
|
|
154
|
+
severity: 'critical',
|
|
155
|
+
reason: 'Large nearly-identical code blocks waste tokens and create maintenance burden',
|
|
156
|
+
suggestion: 'Extract to shared utility module immediately',
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
else if (similarity >= 0.95 && linesOfCode >= 15) {
|
|
160
|
+
return {
|
|
161
|
+
severity: 'major',
|
|
162
|
+
reason: 'Nearly identical code should be consolidated',
|
|
163
|
+
suggestion: 'Move to shared utility file',
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
else if (similarity >= 0.85) {
|
|
167
|
+
return {
|
|
168
|
+
severity: 'major',
|
|
169
|
+
reason: 'High similarity indicates significant duplication',
|
|
170
|
+
suggestion: 'Extract common logic to shared function',
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
else if (similarity >= 0.7) {
|
|
174
|
+
return {
|
|
175
|
+
severity: 'minor',
|
|
176
|
+
reason: 'Moderate similarity detected',
|
|
177
|
+
suggestion: 'Consider extracting shared patterns if code evolves together',
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
return {
|
|
182
|
+
severity: 'minor',
|
|
183
|
+
reason: 'Minor similarity detected',
|
|
184
|
+
suggestion: 'Monitor but refactoring may not be worthwhile',
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Get a human-readable severity label with emoji
|
|
190
|
+
*/
|
|
191
|
+
export function getSeverityLabel(severity) {
|
|
192
|
+
const labels = {
|
|
193
|
+
critical: 'đ´ CRITICAL',
|
|
194
|
+
major: 'đĄ MAJOR',
|
|
195
|
+
minor: 'đĩ MINOR',
|
|
196
|
+
info: 'âšī¸ INFO',
|
|
197
|
+
};
|
|
198
|
+
return labels[severity];
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Filter duplicates by minimum severity threshold
|
|
202
|
+
*/
|
|
203
|
+
export function filterBySeverity(duplicates, minSeverity) {
|
|
204
|
+
const severityOrder = ['info', 'minor', 'major', 'critical'];
|
|
205
|
+
const minIndex = severityOrder.indexOf(minSeverity);
|
|
206
|
+
if (minIndex === -1)
|
|
207
|
+
return duplicates;
|
|
208
|
+
return duplicates.filter((dup) => {
|
|
209
|
+
const dupIndex = severityOrder.indexOf(dup.severity);
|
|
210
|
+
return dupIndex >= minIndex;
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Get severity threshold for filtering
|
|
215
|
+
*/
|
|
216
|
+
export function getSeverityThreshold(severity) {
|
|
217
|
+
const thresholds = {
|
|
218
|
+
critical: 0.95,
|
|
219
|
+
major: 0.85,
|
|
220
|
+
minor: 0.5,
|
|
221
|
+
info: 0,
|
|
222
|
+
};
|
|
223
|
+
return thresholds[severity] || 0;
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=context-rules.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-rules.js","sourceRoot":"","sources":["../src/context-rules.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,6DAA6D;IAC7D;QACE,IAAI,EAAE,eAAe;QACrB,MAAM,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE;YACrB,MAA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AAO,EAAE,UAAU,CAAC,CAAC;IACzE,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IAEpD,IAAI,QAAQ,KAAK,CAAC,CAAC;QAAE,OAAO,UAAU,CAAC;IAEvC,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE;QAC/B,MAAM,QAAQ,GAAG,aAAa,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACrD,OAAO,QAAQ,IAAI,QAAQ,CAAC;IAC9B,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,QAAkB;IACrD,MAAM,UAAU,GAA6B;QAC3C,QAAQ,EAAE,IAAI;QACd,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,GAAG;QACV,IAAI,EAAE,CAAC;KACR,CAAC;IACF,OAAO,UAAU,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,C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