@aiready/pattern-detect 0.16.18 → 0.16.19
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-BVz-HnZd.d.mts +119 -0
- package/dist/analyzer-entry-BwuoiCNm.d.ts +119 -0
- package/dist/analyzer-entry.d.mts +3 -0
- package/dist/analyzer-entry.d.ts +3 -0
- package/dist/analyzer-entry.js +810 -0
- package/dist/analyzer-entry.mjs +12 -0
- package/dist/chunk-I6ETJC7L.mjs +179 -0
- package/dist/chunk-THF4RW63.mjs +254 -0
- package/dist/chunk-UB3CGOQ7.mjs +64 -0
- package/dist/chunk-WBBO35SC.mjs +112 -0
- package/dist/chunk-WMOGJFME.mjs +391 -0
- package/dist/cli.js +37 -76
- package/dist/cli.mjs +52 -79
- package/dist/context-rules-entry-y2uJSngh.d.mts +60 -0
- package/dist/context-rules-entry-y2uJSngh.d.ts +60 -0
- package/dist/context-rules-entry.d.mts +2 -0
- package/dist/context-rules-entry.d.ts +2 -0
- package/dist/context-rules-entry.js +207 -0
- package/dist/context-rules-entry.mjs +12 -0
- package/dist/detector-entry.d.mts +14 -0
- package/dist/detector-entry.d.ts +14 -0
- package/dist/detector-entry.js +418 -0
- package/dist/detector-entry.mjs +7 -0
- package/dist/index.d.mts +7 -235
- package/dist/index.d.ts +7 -235
- package/dist/index.mjs +17 -9
- package/dist/scoring-entry.d.mts +23 -0
- package/dist/scoring-entry.d.ts +23 -0
- package/dist/scoring-entry.js +133 -0
- package/dist/scoring-entry.mjs +6 -0
- package/dist/types-DU2mmhwb.d.mts +36 -0
- package/dist/types-DU2mmhwb.d.ts +36 -0
- package/package.json +24 -4
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Severity, ScanOptions, AnalysisResult } from '@aiready/core';
|
|
2
|
+
import { P as PatternType, D as DuplicatePattern } from './types-DU2mmhwb.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
|
+
interface PatternDetectOptions extends ScanOptions {
|
|
54
|
+
minSimilarity?: number;
|
|
55
|
+
minLines?: number;
|
|
56
|
+
batchSize?: number;
|
|
57
|
+
approx?: boolean;
|
|
58
|
+
minSharedTokens?: number;
|
|
59
|
+
maxCandidatesPerBlock?: number;
|
|
60
|
+
streamResults?: boolean;
|
|
61
|
+
severity?: string;
|
|
62
|
+
includeTests?: boolean;
|
|
63
|
+
useSmartDefaults?: boolean;
|
|
64
|
+
groupByFilePair?: boolean;
|
|
65
|
+
createClusters?: boolean;
|
|
66
|
+
minClusterTokenCost?: number;
|
|
67
|
+
minClusterFiles?: number;
|
|
68
|
+
excludePatterns?: string[];
|
|
69
|
+
confidenceThreshold?: number;
|
|
70
|
+
ignoreWhitelist?: string[];
|
|
71
|
+
onProgress?: (processed: number, total: number, message: string) => void;
|
|
72
|
+
}
|
|
73
|
+
interface PatternSummary {
|
|
74
|
+
totalPatterns: number;
|
|
75
|
+
totalTokenCost: number;
|
|
76
|
+
patternsByType: Record<PatternType, number>;
|
|
77
|
+
topDuplicates: Array<{
|
|
78
|
+
files: Array<{
|
|
79
|
+
path: string;
|
|
80
|
+
startLine: number;
|
|
81
|
+
endLine: number;
|
|
82
|
+
}>;
|
|
83
|
+
similarity: number;
|
|
84
|
+
patternType: PatternType;
|
|
85
|
+
tokenCost: number;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Determine smart defaults based on repository size estimation.
|
|
90
|
+
*
|
|
91
|
+
* @param directory - The directory to analyze for size.
|
|
92
|
+
* @param userOptions - User-provided option overrides.
|
|
93
|
+
* @returns Promise resolving to optimal detection options.
|
|
94
|
+
*/
|
|
95
|
+
declare function getSmartDefaults(directory: string, userOptions: Partial<PatternDetectOptions>): Promise<PatternDetectOptions>;
|
|
96
|
+
/**
|
|
97
|
+
* Main entry point for pattern detection analysis.
|
|
98
|
+
*
|
|
99
|
+
* @param options - Configuration including rootDir and detection parameters.
|
|
100
|
+
* @returns Promise resolving to the comprehensive pattern detect report.
|
|
101
|
+
* @lastUpdated 2026-03-18
|
|
102
|
+
*/
|
|
103
|
+
declare function analyzePatterns(options: PatternDetectOptions): Promise<{
|
|
104
|
+
results: AnalysisResult[];
|
|
105
|
+
duplicates: DuplicatePattern[];
|
|
106
|
+
files: string[];
|
|
107
|
+
groups?: DuplicateGroup[];
|
|
108
|
+
clusters?: RefactorCluster[];
|
|
109
|
+
config: PatternDetectOptions;
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* Generate a summary of pattern detection results.
|
|
113
|
+
*
|
|
114
|
+
* @param results - Array of file-level analysis results.
|
|
115
|
+
* @returns Consolidated pattern summary object.
|
|
116
|
+
*/
|
|
117
|
+
declare function generateSummary(results: AnalysisResult[]): PatternSummary;
|
|
118
|
+
|
|
119
|
+
export { type DuplicateGroup as D, type PatternDetectOptions as P, type RefactorCluster as R, type PatternSummary as a, analyzePatterns as b, createRefactorClusters as c, getSmartDefaults as d, groupDuplicatesByFilePair as e, filterClustersByImpact as f, generateSummary as g };
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { Severity, ScanOptions, 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
|
+
interface PatternDetectOptions extends ScanOptions {
|
|
54
|
+
minSimilarity?: number;
|
|
55
|
+
minLines?: number;
|
|
56
|
+
batchSize?: number;
|
|
57
|
+
approx?: boolean;
|
|
58
|
+
minSharedTokens?: number;
|
|
59
|
+
maxCandidatesPerBlock?: number;
|
|
60
|
+
streamResults?: boolean;
|
|
61
|
+
severity?: string;
|
|
62
|
+
includeTests?: boolean;
|
|
63
|
+
useSmartDefaults?: boolean;
|
|
64
|
+
groupByFilePair?: boolean;
|
|
65
|
+
createClusters?: boolean;
|
|
66
|
+
minClusterTokenCost?: number;
|
|
67
|
+
minClusterFiles?: number;
|
|
68
|
+
excludePatterns?: string[];
|
|
69
|
+
confidenceThreshold?: number;
|
|
70
|
+
ignoreWhitelist?: string[];
|
|
71
|
+
onProgress?: (processed: number, total: number, message: string) => void;
|
|
72
|
+
}
|
|
73
|
+
interface PatternSummary {
|
|
74
|
+
totalPatterns: number;
|
|
75
|
+
totalTokenCost: number;
|
|
76
|
+
patternsByType: Record<PatternType, number>;
|
|
77
|
+
topDuplicates: Array<{
|
|
78
|
+
files: Array<{
|
|
79
|
+
path: string;
|
|
80
|
+
startLine: number;
|
|
81
|
+
endLine: number;
|
|
82
|
+
}>;
|
|
83
|
+
similarity: number;
|
|
84
|
+
patternType: PatternType;
|
|
85
|
+
tokenCost: number;
|
|
86
|
+
}>;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Determine smart defaults based on repository size estimation.
|
|
90
|
+
*
|
|
91
|
+
* @param directory - The directory to analyze for size.
|
|
92
|
+
* @param userOptions - User-provided option overrides.
|
|
93
|
+
* @returns Promise resolving to optimal detection options.
|
|
94
|
+
*/
|
|
95
|
+
declare function getSmartDefaults(directory: string, userOptions: Partial<PatternDetectOptions>): Promise<PatternDetectOptions>;
|
|
96
|
+
/**
|
|
97
|
+
* Main entry point for pattern detection analysis.
|
|
98
|
+
*
|
|
99
|
+
* @param options - Configuration including rootDir and detection parameters.
|
|
100
|
+
* @returns Promise resolving to the comprehensive pattern detect report.
|
|
101
|
+
* @lastUpdated 2026-03-18
|
|
102
|
+
*/
|
|
103
|
+
declare function analyzePatterns(options: PatternDetectOptions): Promise<{
|
|
104
|
+
results: AnalysisResult[];
|
|
105
|
+
duplicates: DuplicatePattern[];
|
|
106
|
+
files: string[];
|
|
107
|
+
groups?: DuplicateGroup[];
|
|
108
|
+
clusters?: RefactorCluster[];
|
|
109
|
+
config: PatternDetectOptions;
|
|
110
|
+
}>;
|
|
111
|
+
/**
|
|
112
|
+
* Generate a summary of pattern detection results.
|
|
113
|
+
*
|
|
114
|
+
* @param results - Array of file-level analysis results.
|
|
115
|
+
* @returns Consolidated pattern summary object.
|
|
116
|
+
*/
|
|
117
|
+
declare function generateSummary(results: AnalysisResult[]): PatternSummary;
|
|
118
|
+
|
|
119
|
+
export { type DuplicateGroup as D, type PatternDetectOptions as P, type RefactorCluster as R, type PatternSummary as a, analyzePatterns as b, createRefactorClusters as c, getSmartDefaults as d, groupDuplicatesByFilePair as e, filterClustersByImpact as f, generateSummary as g };
|