@aiready/pattern-detect 0.17.15 → 0.17.16
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 +2 -2
- package/dist/analyzer-entry/index.d.ts +2 -2
- package/dist/analyzer-entry/index.js +357 -140
- package/dist/analyzer-entry/index.mjs +4 -4
- package/dist/chunk-3LMYFYWG.mjs +514 -0
- package/dist/chunk-4YXKUW4P.mjs +143 -0
- package/dist/chunk-5A3ULAQ5.mjs +571 -0
- package/dist/chunk-5FACKJ7M.mjs +519 -0
- package/dist/chunk-6B72OWZA.mjs +143 -0
- package/dist/chunk-6SHBBRHF.mjs +600 -0
- package/dist/chunk-BKSIA7A2.mjs +516 -0
- package/dist/chunk-CM5YJR7G.mjs +516 -0
- package/dist/chunk-FSXOU23F.mjs +620 -0
- package/dist/chunk-GUYQI3AF.mjs +514 -0
- package/dist/chunk-H2TGXGMX.mjs +587 -0
- package/dist/chunk-KMAOEVRS.mjs +150 -0
- package/dist/chunk-NWG2ZIGX.mjs +146 -0
- package/dist/chunk-OFVJFGQW.mjs +514 -0
- package/dist/chunk-PCCZREHY.mjs +143 -0
- package/dist/chunk-PQS5ACTN.mjs +516 -0
- package/dist/chunk-TVE75IDM.mjs +143 -0
- package/dist/chunk-UDOGQ42Q.mjs +603 -0
- package/dist/chunk-UFI4UDQI.mjs +514 -0
- package/dist/chunk-UXV57HN3.mjs +144 -0
- package/dist/chunk-VC2BOV6R.mjs +143 -0
- package/dist/chunk-VI2OVG73.mjs +514 -0
- package/dist/chunk-VKGYNHFY.mjs +514 -0
- package/dist/chunk-WBLZYAQ2.mjs +518 -0
- package/dist/chunk-WFVXMMB3.mjs +143 -0
- package/dist/chunk-WQC43BIO.mjs +516 -0
- package/dist/chunk-WTAIM3SG.mjs +146 -0
- package/dist/chunk-XC7U55PE.mjs +514 -0
- package/dist/chunk-XR373Q6G.mjs +146 -0
- package/dist/chunk-XWIBTD67.mjs +620 -0
- package/dist/chunk-YUQ2VQVJ.mjs +514 -0
- package/dist/chunk-Z4NOH52X.mjs +143 -0
- package/dist/cli.js +357 -140
- package/dist/cli.mjs +4 -4
- package/dist/context-rules-entry/index.js +351 -139
- package/dist/context-rules-entry/index.mjs +1 -1
- package/dist/detector-entry/index.d.mts +2 -2
- package/dist/detector-entry/index.d.ts +2 -2
- package/dist/detector-entry/index.js +355 -140
- package/dist/detector-entry/index.mjs +2 -2
- package/dist/index-BGvkJ9j1.d.mts +136 -0
- package/dist/index-BJq32qmj.d.mts +137 -0
- package/dist/index-BpoJSgX-.d.mts +136 -0
- package/dist/index-C7qLPKmH.d.ts +150 -0
- package/dist/index-CThnG9hv.d.ts +155 -0
- package/dist/index-D0Hpg9nN.d.mts +150 -0
- package/dist/index-DN6XpBOW.d.mts +155 -0
- package/dist/index-F8xqZ2PS.d.ts +136 -0
- package/dist/index-HNhDr6CV.d.ts +137 -0
- package/dist/index-ux0Wo8Ps.d.ts +136 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +359 -142
- package/dist/index.mjs +4 -4
- package/dist/scoring-entry/index.d.mts +1 -1
- package/dist/scoring-entry/index.d.ts +1 -1
- package/dist/scoring-entry/index.js +2 -2
- package/dist/scoring-entry/index.mjs +1 -1
- package/dist/types-tgrmUrHE.d.mts +37 -0
- package/dist/types-tgrmUrHE.d.ts +37 -0
- package/package.json +5 -3
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Severity, ScanOptions, Issue, AnalysisResult } from '@aiready/core';
|
|
2
|
+
import { P as PatternType, D as DuplicatePattern } from './types-tgrmUrHE.js';
|
|
3
|
+
|
|
4
|
+
interface DuplicateGroup {
|
|
5
|
+
filePair: string;
|
|
6
|
+
severity: Severity;
|
|
7
|
+
occurrences: number;
|
|
8
|
+
totalTokenCost: number;
|
|
9
|
+
averageSimilarity: number;
|
|
10
|
+
patternTypes: Set<PatternType>;
|
|
11
|
+
lineRanges: Array<{
|
|
12
|
+
file1: {
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
};
|
|
16
|
+
file2: {
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
interface RefactorCluster {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
files: string[];
|
|
26
|
+
severity: Severity;
|
|
27
|
+
duplicateCount: number;
|
|
28
|
+
totalTokenCost: number;
|
|
29
|
+
averageSimilarity: number;
|
|
30
|
+
reason?: string;
|
|
31
|
+
suggestion?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Group raw duplicates by file pairs to reduce noise
|
|
35
|
+
*/
|
|
36
|
+
declare function groupDuplicatesByFilePair(duplicates: DuplicatePattern[]): DuplicateGroup[];
|
|
37
|
+
/**
|
|
38
|
+
* Create clusters of highly related files (refactor targets)
|
|
39
|
+
* Uses a simple connected components algorithm
|
|
40
|
+
* @param duplicates - Array of duplicate patterns to cluster
|
|
41
|
+
* @returns Array of refactor clusters
|
|
42
|
+
*/
|
|
43
|
+
declare function createRefactorClusters(duplicates: DuplicatePattern[]): RefactorCluster[];
|
|
44
|
+
/**
|
|
45
|
+
* Filter clusters by impact threshold
|
|
46
|
+
* @param clusters - Array of refactor clusters to filter
|
|
47
|
+
* @param minTokenCost - Minimum token cost threshold (default: 1000)
|
|
48
|
+
* @param minFiles - Minimum number of files in cluster (default: 3)
|
|
49
|
+
* @returns Filtered array of refactor clusters
|
|
50
|
+
*/
|
|
51
|
+
declare function filterClustersByImpact(clusters: RefactorCluster[], minTokenCost?: number, minFiles?: number): RefactorCluster[];
|
|
52
|
+
/**
|
|
53
|
+
* Detect if two duplicate files are likely brand-specific variants
|
|
54
|
+
* (e.g., different themed versions of the same UI component)
|
|
55
|
+
*
|
|
56
|
+
* @param file1 - Path to the first file
|
|
57
|
+
* @param file2 - Path to the second file
|
|
58
|
+
* @param code1 - Content of the first file
|
|
59
|
+
* @param code2 - Content of the second file
|
|
60
|
+
*/
|
|
61
|
+
declare function areBrandSpecificVariants(file1: string, file2: string, code1: string, code2: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Filter out brand-specific variants from duplicates
|
|
64
|
+
*/
|
|
65
|
+
declare function filterBrandSpecificVariants(duplicates: DuplicatePattern[]): DuplicatePattern[];
|
|
66
|
+
|
|
67
|
+
interface PatternDetectOptions extends ScanOptions {
|
|
68
|
+
minSimilarity?: number;
|
|
69
|
+
minLines?: number;
|
|
70
|
+
batchSize?: number;
|
|
71
|
+
approx?: boolean;
|
|
72
|
+
minSharedTokens?: number;
|
|
73
|
+
maxCandidatesPerBlock?: number;
|
|
74
|
+
streamResults?: boolean;
|
|
75
|
+
useSmartDefaults?: boolean;
|
|
76
|
+
groupByFilePair?: boolean;
|
|
77
|
+
createClusters?: boolean;
|
|
78
|
+
minClusterTokenCost?: number;
|
|
79
|
+
minClusterFiles?: number;
|
|
80
|
+
excludePatterns?: string[];
|
|
81
|
+
excludeFiles?: string[];
|
|
82
|
+
confidenceThreshold?: number;
|
|
83
|
+
ignoreWhitelist?: string[];
|
|
84
|
+
onProgress?: (processed: number, total: number, message: string) => void;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Determine smart defaults based on repository size estimation.
|
|
88
|
+
*/
|
|
89
|
+
declare function getSmartDefaults(directory: string, userOptions: Partial<PatternDetectOptions>): Promise<PatternDetectOptions>;
|
|
90
|
+
/**
|
|
91
|
+
* Log current configuration settings to the console.
|
|
92
|
+
*/
|
|
93
|
+
declare function logConfiguration(config: PatternDetectOptions, estimatedBlocks: number): void;
|
|
94
|
+
|
|
95
|
+
interface PatternSummary {
|
|
96
|
+
totalPatterns: number;
|
|
97
|
+
totalTokenCost: number;
|
|
98
|
+
patternsByType: Record<PatternType, number>;
|
|
99
|
+
topDuplicates: Array<{
|
|
100
|
+
files: Array<{
|
|
101
|
+
path: string;
|
|
102
|
+
startLine: number;
|
|
103
|
+
endLine: number;
|
|
104
|
+
}>;
|
|
105
|
+
similarity: number;
|
|
106
|
+
patternType: PatternType;
|
|
107
|
+
tokenCost: number;
|
|
108
|
+
}>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Generate a summary of pattern detection results.
|
|
112
|
+
*
|
|
113
|
+
* @param results - Array of raw analysis results from the detector
|
|
114
|
+
* @returns Structured pattern summary and top duplicates
|
|
115
|
+
*/
|
|
116
|
+
declare function generateSummary(results: AnalysisResult[]): PatternSummary;
|
|
117
|
+
/**
|
|
118
|
+
* Filter issues by severity level.
|
|
119
|
+
*
|
|
120
|
+
* @param issues - List of detected issues
|
|
121
|
+
* @param severity - Severity filter: 'all' | 'critical' | 'high' | 'medium'
|
|
122
|
+
* @returns Filtered list of issues
|
|
123
|
+
*/
|
|
124
|
+
declare function filterBySeverity(issues: Issue[], severity: string): Issue[];
|
|
125
|
+
/**
|
|
126
|
+
* Get human-readable label for severity.
|
|
127
|
+
*
|
|
128
|
+
* @param severity - The core severity type
|
|
129
|
+
* @returns String representation: 'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW'
|
|
130
|
+
*/
|
|
131
|
+
declare function getSeverityLabel(severity: Severity): string;
|
|
132
|
+
/**
|
|
133
|
+
* Calculate severity based on similarity.
|
|
134
|
+
*
|
|
135
|
+
* @param similarity - Similarity score from 0 to 1
|
|
136
|
+
* @returns The calculated core severity level
|
|
137
|
+
*/
|
|
138
|
+
declare function calculateSeverity(similarity: number): Severity;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Main entry point for pattern detection analysis.
|
|
142
|
+
*
|
|
143
|
+
* @param options - Configuration including rootDir and detection parameters.
|
|
144
|
+
* @returns Promise resolving to the comprehensive pattern detect report.
|
|
145
|
+
*/
|
|
146
|
+
declare function analyzePatterns(options: PatternDetectOptions): Promise<{
|
|
147
|
+
results: AnalysisResult[];
|
|
148
|
+
duplicates: DuplicatePattern[];
|
|
149
|
+
files: string[];
|
|
150
|
+
groups?: DuplicateGroup[];
|
|
151
|
+
clusters?: RefactorCluster[];
|
|
152
|
+
config: PatternDetectOptions;
|
|
153
|
+
}>;
|
|
154
|
+
|
|
155
|
+
export { type DuplicateGroup as D, type PatternDetectOptions as P, type RefactorCluster as R, type PatternSummary as a, analyzePatterns as b, areBrandSpecificVariants as c, calculateSeverity as d, createRefactorClusters as e, filterBrandSpecificVariants as f, filterBySeverity as g, filterClustersByImpact as h, generateSummary as i, getSeverityLabel as j, getSmartDefaults as k, groupDuplicatesByFilePair as l, logConfiguration as m };
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Severity, ScanOptions, Issue, AnalysisResult } from '@aiready/core';
|
|
2
|
+
import { P as PatternType, D as DuplicatePattern } from './types-tgrmUrHE.mjs';
|
|
3
|
+
|
|
4
|
+
interface DuplicateGroup {
|
|
5
|
+
filePair: string;
|
|
6
|
+
severity: Severity;
|
|
7
|
+
occurrences: number;
|
|
8
|
+
totalTokenCost: number;
|
|
9
|
+
averageSimilarity: number;
|
|
10
|
+
patternTypes: Set<PatternType>;
|
|
11
|
+
lineRanges: Array<{
|
|
12
|
+
file1: {
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
};
|
|
16
|
+
file2: {
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
interface RefactorCluster {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
files: string[];
|
|
26
|
+
severity: Severity;
|
|
27
|
+
duplicateCount: number;
|
|
28
|
+
totalTokenCost: number;
|
|
29
|
+
averageSimilarity: number;
|
|
30
|
+
reason?: string;
|
|
31
|
+
suggestion?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Group raw duplicates by file pairs to reduce noise
|
|
35
|
+
*/
|
|
36
|
+
declare function groupDuplicatesByFilePair(duplicates: DuplicatePattern[]): DuplicateGroup[];
|
|
37
|
+
/**
|
|
38
|
+
* Create clusters of highly related files (refactor targets)
|
|
39
|
+
* Uses a simple connected components algorithm
|
|
40
|
+
* @param duplicates - Array of duplicate patterns to cluster
|
|
41
|
+
* @returns Array of refactor clusters
|
|
42
|
+
*/
|
|
43
|
+
declare function createRefactorClusters(duplicates: DuplicatePattern[]): RefactorCluster[];
|
|
44
|
+
/**
|
|
45
|
+
* Filter clusters by impact threshold
|
|
46
|
+
* @param clusters - Array of refactor clusters to filter
|
|
47
|
+
* @param minTokenCost - Minimum token cost threshold (default: 1000)
|
|
48
|
+
* @param minFiles - Minimum number of files in cluster (default: 3)
|
|
49
|
+
* @returns Filtered array of refactor clusters
|
|
50
|
+
*/
|
|
51
|
+
declare function filterClustersByImpact(clusters: RefactorCluster[], minTokenCost?: number, minFiles?: number): RefactorCluster[];
|
|
52
|
+
/**
|
|
53
|
+
* Detect if two duplicate files are likely brand-specific variants
|
|
54
|
+
* (e.g., different themed versions of the same UI component)
|
|
55
|
+
*/
|
|
56
|
+
declare function areBrandSpecificVariants(file1: string, file2: string, code1: string, code2: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Filter out brand-specific variants from duplicates
|
|
59
|
+
*/
|
|
60
|
+
declare function filterBrandSpecificVariants(duplicates: DuplicatePattern[]): DuplicatePattern[];
|
|
61
|
+
|
|
62
|
+
interface PatternDetectOptions extends ScanOptions {
|
|
63
|
+
minSimilarity?: number;
|
|
64
|
+
minLines?: number;
|
|
65
|
+
batchSize?: number;
|
|
66
|
+
approx?: boolean;
|
|
67
|
+
minSharedTokens?: number;
|
|
68
|
+
maxCandidatesPerBlock?: number;
|
|
69
|
+
streamResults?: boolean;
|
|
70
|
+
useSmartDefaults?: boolean;
|
|
71
|
+
groupByFilePair?: boolean;
|
|
72
|
+
createClusters?: boolean;
|
|
73
|
+
minClusterTokenCost?: number;
|
|
74
|
+
minClusterFiles?: number;
|
|
75
|
+
excludePatterns?: string[];
|
|
76
|
+
excludeFiles?: string[];
|
|
77
|
+
confidenceThreshold?: number;
|
|
78
|
+
ignoreWhitelist?: string[];
|
|
79
|
+
onProgress?: (processed: number, total: number, message: string) => void;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Determine smart defaults based on repository size estimation.
|
|
83
|
+
*/
|
|
84
|
+
declare function getSmartDefaults(directory: string, userOptions: Partial<PatternDetectOptions>): Promise<PatternDetectOptions>;
|
|
85
|
+
/**
|
|
86
|
+
* Log current configuration settings to the console.
|
|
87
|
+
*/
|
|
88
|
+
declare function logConfiguration(config: PatternDetectOptions, estimatedBlocks: number): void;
|
|
89
|
+
|
|
90
|
+
interface PatternSummary {
|
|
91
|
+
totalPatterns: number;
|
|
92
|
+
totalTokenCost: number;
|
|
93
|
+
patternsByType: Record<PatternType, number>;
|
|
94
|
+
topDuplicates: Array<{
|
|
95
|
+
files: Array<{
|
|
96
|
+
path: string;
|
|
97
|
+
startLine: number;
|
|
98
|
+
endLine: number;
|
|
99
|
+
}>;
|
|
100
|
+
similarity: number;
|
|
101
|
+
patternType: PatternType;
|
|
102
|
+
tokenCost: number;
|
|
103
|
+
}>;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Generate a summary of pattern detection results.
|
|
107
|
+
*
|
|
108
|
+
* @param results - Array of raw analysis results from the detector
|
|
109
|
+
* @returns Structured pattern summary and top duplicates
|
|
110
|
+
*/
|
|
111
|
+
declare function generateSummary(results: AnalysisResult[]): PatternSummary;
|
|
112
|
+
/**
|
|
113
|
+
* Filter issues by severity level.
|
|
114
|
+
*
|
|
115
|
+
* @param issues - List of detected issues
|
|
116
|
+
* @param severity - Severity filter: 'all' | 'critical' | 'high' | 'medium'
|
|
117
|
+
* @returns Filtered list of issues
|
|
118
|
+
*/
|
|
119
|
+
declare function filterBySeverity(issues: Issue[], severity: string): Issue[];
|
|
120
|
+
/**
|
|
121
|
+
* Get human-readable label for severity.
|
|
122
|
+
*
|
|
123
|
+
* @param severity - The core severity type
|
|
124
|
+
* @returns String representation: 'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW'
|
|
125
|
+
*/
|
|
126
|
+
declare function getSeverityLabel(severity: Severity): string;
|
|
127
|
+
/**
|
|
128
|
+
* Calculate severity based on similarity.
|
|
129
|
+
*
|
|
130
|
+
* @param similarity - Similarity score from 0 to 1
|
|
131
|
+
* @returns The calculated core severity level
|
|
132
|
+
*/
|
|
133
|
+
declare function calculateSeverity(similarity: number): Severity;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Main entry point for pattern detection analysis.
|
|
137
|
+
*
|
|
138
|
+
* @param options - Configuration including rootDir and detection parameters.
|
|
139
|
+
* @returns Promise resolving to the comprehensive pattern detect report.
|
|
140
|
+
*/
|
|
141
|
+
declare function analyzePatterns(options: PatternDetectOptions): Promise<{
|
|
142
|
+
results: AnalysisResult[];
|
|
143
|
+
duplicates: DuplicatePattern[];
|
|
144
|
+
files: string[];
|
|
145
|
+
groups?: DuplicateGroup[];
|
|
146
|
+
clusters?: RefactorCluster[];
|
|
147
|
+
config: PatternDetectOptions;
|
|
148
|
+
}>;
|
|
149
|
+
|
|
150
|
+
export { type DuplicateGroup as D, type PatternDetectOptions as P, type RefactorCluster as R, type PatternSummary as a, analyzePatterns as b, areBrandSpecificVariants as c, calculateSeverity as d, createRefactorClusters as e, filterBrandSpecificVariants as f, filterBySeverity as g, filterClustersByImpact as h, generateSummary as i, getSeverityLabel as j, getSmartDefaults as k, groupDuplicatesByFilePair as l, logConfiguration as m };
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { Severity, ScanOptions, Issue, AnalysisResult } from '@aiready/core';
|
|
2
|
+
import { P as PatternType, D as DuplicatePattern } from './types-tgrmUrHE.mjs';
|
|
3
|
+
|
|
4
|
+
interface DuplicateGroup {
|
|
5
|
+
filePair: string;
|
|
6
|
+
severity: Severity;
|
|
7
|
+
occurrences: number;
|
|
8
|
+
totalTokenCost: number;
|
|
9
|
+
averageSimilarity: number;
|
|
10
|
+
patternTypes: Set<PatternType>;
|
|
11
|
+
lineRanges: Array<{
|
|
12
|
+
file1: {
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
};
|
|
16
|
+
file2: {
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
interface RefactorCluster {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
files: string[];
|
|
26
|
+
severity: Severity;
|
|
27
|
+
duplicateCount: number;
|
|
28
|
+
totalTokenCost: number;
|
|
29
|
+
averageSimilarity: number;
|
|
30
|
+
reason?: string;
|
|
31
|
+
suggestion?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Group raw duplicates by file pairs to reduce noise
|
|
35
|
+
*/
|
|
36
|
+
declare function groupDuplicatesByFilePair(duplicates: DuplicatePattern[]): DuplicateGroup[];
|
|
37
|
+
/**
|
|
38
|
+
* Create clusters of highly related files (refactor targets)
|
|
39
|
+
* Uses a simple connected components algorithm
|
|
40
|
+
* @param duplicates - Array of duplicate patterns to cluster
|
|
41
|
+
* @returns Array of refactor clusters
|
|
42
|
+
*/
|
|
43
|
+
declare function createRefactorClusters(duplicates: DuplicatePattern[]): RefactorCluster[];
|
|
44
|
+
/**
|
|
45
|
+
* Filter clusters by impact threshold
|
|
46
|
+
* @param clusters - Array of refactor clusters to filter
|
|
47
|
+
* @param minTokenCost - Minimum token cost threshold (default: 1000)
|
|
48
|
+
* @param minFiles - Minimum number of files in cluster (default: 3)
|
|
49
|
+
* @returns Filtered array of refactor clusters
|
|
50
|
+
*/
|
|
51
|
+
declare function filterClustersByImpact(clusters: RefactorCluster[], minTokenCost?: number, minFiles?: number): RefactorCluster[];
|
|
52
|
+
/**
|
|
53
|
+
* Detect if two duplicate files are likely brand-specific variants
|
|
54
|
+
* (e.g., different themed versions of the same UI component)
|
|
55
|
+
*
|
|
56
|
+
* @param file1 - Path to the first file
|
|
57
|
+
* @param file2 - Path to the second file
|
|
58
|
+
* @param code1 - Content of the first file
|
|
59
|
+
* @param code2 - Content of the second file
|
|
60
|
+
*/
|
|
61
|
+
declare function areBrandSpecificVariants(file1: string, file2: string, code1: string, code2: string): boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Filter out brand-specific variants from duplicates
|
|
64
|
+
*/
|
|
65
|
+
declare function filterBrandSpecificVariants(duplicates: DuplicatePattern[]): DuplicatePattern[];
|
|
66
|
+
|
|
67
|
+
interface PatternDetectOptions extends ScanOptions {
|
|
68
|
+
minSimilarity?: number;
|
|
69
|
+
minLines?: number;
|
|
70
|
+
batchSize?: number;
|
|
71
|
+
approx?: boolean;
|
|
72
|
+
minSharedTokens?: number;
|
|
73
|
+
maxCandidatesPerBlock?: number;
|
|
74
|
+
streamResults?: boolean;
|
|
75
|
+
useSmartDefaults?: boolean;
|
|
76
|
+
groupByFilePair?: boolean;
|
|
77
|
+
createClusters?: boolean;
|
|
78
|
+
minClusterTokenCost?: number;
|
|
79
|
+
minClusterFiles?: number;
|
|
80
|
+
excludePatterns?: string[];
|
|
81
|
+
excludeFiles?: string[];
|
|
82
|
+
confidenceThreshold?: number;
|
|
83
|
+
ignoreWhitelist?: string[];
|
|
84
|
+
onProgress?: (processed: number, total: number, message: string) => void;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Determine smart defaults based on repository size estimation.
|
|
88
|
+
*/
|
|
89
|
+
declare function getSmartDefaults(directory: string, userOptions: Partial<PatternDetectOptions>): Promise<PatternDetectOptions>;
|
|
90
|
+
/**
|
|
91
|
+
* Log current configuration settings to the console.
|
|
92
|
+
*/
|
|
93
|
+
declare function logConfiguration(config: PatternDetectOptions, estimatedBlocks: number): void;
|
|
94
|
+
|
|
95
|
+
interface PatternSummary {
|
|
96
|
+
totalPatterns: number;
|
|
97
|
+
totalTokenCost: number;
|
|
98
|
+
patternsByType: Record<PatternType, number>;
|
|
99
|
+
topDuplicates: Array<{
|
|
100
|
+
files: Array<{
|
|
101
|
+
path: string;
|
|
102
|
+
startLine: number;
|
|
103
|
+
endLine: number;
|
|
104
|
+
}>;
|
|
105
|
+
similarity: number;
|
|
106
|
+
patternType: PatternType;
|
|
107
|
+
tokenCost: number;
|
|
108
|
+
}>;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Generate a summary of pattern detection results.
|
|
112
|
+
*
|
|
113
|
+
* @param results - Array of raw analysis results from the detector
|
|
114
|
+
* @returns Structured pattern summary and top duplicates
|
|
115
|
+
*/
|
|
116
|
+
declare function generateSummary(results: AnalysisResult[]): PatternSummary;
|
|
117
|
+
/**
|
|
118
|
+
* Filter issues by severity level.
|
|
119
|
+
*
|
|
120
|
+
* @param issues - List of detected issues
|
|
121
|
+
* @param severity - Severity filter: 'all' | 'critical' | 'high' | 'medium'
|
|
122
|
+
* @returns Filtered list of issues
|
|
123
|
+
*/
|
|
124
|
+
declare function filterBySeverity(issues: Issue[], severity: string): Issue[];
|
|
125
|
+
/**
|
|
126
|
+
* Get human-readable label for severity.
|
|
127
|
+
*
|
|
128
|
+
* @param severity - The core severity type
|
|
129
|
+
* @returns String representation: 'CRITICAL' | 'HIGH' | 'MEDIUM' | 'LOW'
|
|
130
|
+
*/
|
|
131
|
+
declare function getSeverityLabel(severity: Severity): string;
|
|
132
|
+
/**
|
|
133
|
+
* Calculate severity based on similarity.
|
|
134
|
+
*
|
|
135
|
+
* @param similarity - Similarity score from 0 to 1
|
|
136
|
+
* @returns The calculated core severity level
|
|
137
|
+
*/
|
|
138
|
+
declare function calculateSeverity(similarity: number): Severity;
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Main entry point for pattern detection analysis.
|
|
142
|
+
*
|
|
143
|
+
* @param options - Configuration including rootDir and detection parameters.
|
|
144
|
+
* @returns Promise resolving to the comprehensive pattern detect report.
|
|
145
|
+
*/
|
|
146
|
+
declare function analyzePatterns(options: PatternDetectOptions): Promise<{
|
|
147
|
+
results: AnalysisResult[];
|
|
148
|
+
duplicates: DuplicatePattern[];
|
|
149
|
+
files: string[];
|
|
150
|
+
groups?: DuplicateGroup[];
|
|
151
|
+
clusters?: RefactorCluster[];
|
|
152
|
+
config: PatternDetectOptions;
|
|
153
|
+
}>;
|
|
154
|
+
|
|
155
|
+
export { type DuplicateGroup as D, type PatternDetectOptions as P, type RefactorCluster as R, type PatternSummary as a, analyzePatterns as b, areBrandSpecificVariants as c, calculateSeverity as d, createRefactorClusters as e, filterBrandSpecificVariants as f, filterBySeverity as g, filterClustersByImpact as h, generateSummary as i, getSeverityLabel as j, getSmartDefaults as k, groupDuplicatesByFilePair as l, logConfiguration as m };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import { Severity, ScanOptions, Issue, AnalysisResult } from '@aiready/core';
|
|
2
|
+
import { P as PatternType, D as DuplicatePattern } from './types-DU2mmhwb.js';
|
|
3
|
+
|
|
4
|
+
interface DuplicateGroup {
|
|
5
|
+
filePair: string;
|
|
6
|
+
severity: Severity;
|
|
7
|
+
occurrences: number;
|
|
8
|
+
totalTokenCost: number;
|
|
9
|
+
averageSimilarity: number;
|
|
10
|
+
patternTypes: Set<PatternType>;
|
|
11
|
+
lineRanges: Array<{
|
|
12
|
+
file1: {
|
|
13
|
+
start: number;
|
|
14
|
+
end: number;
|
|
15
|
+
};
|
|
16
|
+
file2: {
|
|
17
|
+
start: number;
|
|
18
|
+
end: number;
|
|
19
|
+
};
|
|
20
|
+
}>;
|
|
21
|
+
}
|
|
22
|
+
interface RefactorCluster {
|
|
23
|
+
id: string;
|
|
24
|
+
name: string;
|
|
25
|
+
files: string[];
|
|
26
|
+
severity: Severity;
|
|
27
|
+
duplicateCount: number;
|
|
28
|
+
totalTokenCost: number;
|
|
29
|
+
averageSimilarity: number;
|
|
30
|
+
reason?: string;
|
|
31
|
+
suggestion?: string;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Group raw duplicates by file pairs to reduce noise
|
|
35
|
+
*/
|
|
36
|
+
declare function groupDuplicatesByFilePair(duplicates: DuplicatePattern[]): DuplicateGroup[];
|
|
37
|
+
/**
|
|
38
|
+
* Create clusters of highly related files (refactor targets)
|
|
39
|
+
* Uses a simple connected components algorithm
|
|
40
|
+
* @param duplicates - Array of duplicate patterns to cluster
|
|
41
|
+
* @returns Array of refactor clusters
|
|
42
|
+
*/
|
|
43
|
+
declare function createRefactorClusters(duplicates: DuplicatePattern[]): RefactorCluster[];
|
|
44
|
+
/**
|
|
45
|
+
* Filter clusters by impact threshold
|
|
46
|
+
* @param clusters - Array of refactor clusters to filter
|
|
47
|
+
* @param minTokenCost - Minimum token cost threshold (default: 1000)
|
|
48
|
+
* @param minFiles - Minimum number of files in cluster (default: 3)
|
|
49
|
+
* @returns Filtered array of refactor clusters
|
|
50
|
+
*/
|
|
51
|
+
declare function filterClustersByImpact(clusters: RefactorCluster[], minTokenCost?: number, minFiles?: number): RefactorCluster[];
|
|
52
|
+
/**
|
|
53
|
+
* Detect if two duplicate files are likely brand-specific variants
|
|
54
|
+
* (e.g., different themed versions of the same UI component)
|
|
55
|
+
*/
|
|
56
|
+
declare function areBrandSpecificVariants(file1: string, file2: string, code1: string, code2: string): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Filter out brand-specific variants from duplicates
|
|
59
|
+
*/
|
|
60
|
+
declare function filterBrandSpecificVariants(duplicates: DuplicatePattern[]): DuplicatePattern[];
|
|
61
|
+
|
|
62
|
+
interface PatternDetectOptions extends ScanOptions {
|
|
63
|
+
minSimilarity?: number;
|
|
64
|
+
minLines?: number;
|
|
65
|
+
batchSize?: number;
|
|
66
|
+
approx?: boolean;
|
|
67
|
+
minSharedTokens?: number;
|
|
68
|
+
maxCandidatesPerBlock?: number;
|
|
69
|
+
streamResults?: boolean;
|
|
70
|
+
useSmartDefaults?: boolean;
|
|
71
|
+
groupByFilePair?: boolean;
|
|
72
|
+
createClusters?: boolean;
|
|
73
|
+
minClusterTokenCost?: number;
|
|
74
|
+
minClusterFiles?: number;
|
|
75
|
+
excludePatterns?: string[];
|
|
76
|
+
confidenceThreshold?: number;
|
|
77
|
+
ignoreWhitelist?: string[];
|
|
78
|
+
onProgress?: (processed: number, total: number, message: string) => void;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Determine smart defaults based on repository size estimation.
|
|
82
|
+
*/
|
|
83
|
+
declare function getSmartDefaults(directory: string, userOptions: Partial<PatternDetectOptions>): Promise<PatternDetectOptions>;
|
|
84
|
+
/**
|
|
85
|
+
* Log current configuration settings to the console.
|
|
86
|
+
*/
|
|
87
|
+
declare function logConfiguration(config: PatternDetectOptions, estimatedBlocks: number): void;
|
|
88
|
+
|
|
89
|
+
interface PatternSummary {
|
|
90
|
+
totalPatterns: number;
|
|
91
|
+
totalTokenCost: number;
|
|
92
|
+
patternsByType: Record<PatternType, number>;
|
|
93
|
+
topDuplicates: Array<{
|
|
94
|
+
files: Array<{
|
|
95
|
+
path: string;
|
|
96
|
+
startLine: number;
|
|
97
|
+
endLine: number;
|
|
98
|
+
}>;
|
|
99
|
+
similarity: number;
|
|
100
|
+
patternType: PatternType;
|
|
101
|
+
tokenCost: number;
|
|
102
|
+
}>;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Generate a summary of pattern detection results.
|
|
106
|
+
*/
|
|
107
|
+
declare function generateSummary(results: AnalysisResult[]): PatternSummary;
|
|
108
|
+
/**
|
|
109
|
+
* Filter issues by severity level.
|
|
110
|
+
*/
|
|
111
|
+
declare function filterBySeverity(issues: Issue[], severity: string): Issue[];
|
|
112
|
+
/**
|
|
113
|
+
* Get human-readable label for severity.
|
|
114
|
+
*/
|
|
115
|
+
declare function getSeverityLabel(severity: Severity): string;
|
|
116
|
+
/**
|
|
117
|
+
* Calculate severity based on similarity.
|
|
118
|
+
*/
|
|
119
|
+
declare function calculateSeverity(similarity: number): Severity;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Main entry point for pattern detection analysis.
|
|
123
|
+
*
|
|
124
|
+
* @param options - Configuration including rootDir and detection parameters.
|
|
125
|
+
* @returns Promise resolving to the comprehensive pattern detect report.
|
|
126
|
+
*/
|
|
127
|
+
declare function analyzePatterns(options: PatternDetectOptions): Promise<{
|
|
128
|
+
results: AnalysisResult[];
|
|
129
|
+
duplicates: DuplicatePattern[];
|
|
130
|
+
files: string[];
|
|
131
|
+
groups?: DuplicateGroup[];
|
|
132
|
+
clusters?: RefactorCluster[];
|
|
133
|
+
config: PatternDetectOptions;
|
|
134
|
+
}>;
|
|
135
|
+
|
|
136
|
+
export { type DuplicateGroup as D, type PatternDetectOptions as P, type RefactorCluster as R, type PatternSummary as a, analyzePatterns as b, areBrandSpecificVariants as c, calculateSeverity as d, createRefactorClusters as e, filterBrandSpecificVariants as f, filterBySeverity as g, filterClustersByImpact as h, generateSummary as i, getSeverityLabel as j, getSmartDefaults as k, groupDuplicatesByFilePair as l, logConfiguration as m };
|