@aiready/pattern-detect 0.16.20 → 0.16.22
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 +3 -0
- package/dist/analyzer-entry/index.d.ts +3 -0
- package/dist/analyzer-entry/index.js +693 -0
- package/dist/analyzer-entry/index.mjs +12 -0
- package/dist/analyzer-entry.d.mts +100 -3
- package/dist/analyzer-entry.d.ts +100 -3
- package/dist/context-rules-entry/index.d.mts +2 -0
- package/dist/context-rules-entry/index.d.ts +2 -0
- package/dist/context-rules-entry/index.js +207 -0
- package/dist/context-rules-entry/index.mjs +12 -0
- package/dist/context-rules-entry.d.mts +55 -2
- package/dist/context-rules-entry.d.ts +55 -2
- package/dist/detector-entry/index.d.mts +14 -0
- package/dist/detector-entry/index.d.ts +14 -0
- package/dist/detector-entry/index.js +301 -0
- package/dist/detector-entry/index.mjs +7 -0
- package/dist/detector-entry.d.mts +2 -2
- package/dist/detector-entry.d.ts +2 -2
- package/dist/index-BVz-HnZd.d.mts +119 -0
- package/dist/index-BwuoiCNm.d.ts +119 -0
- package/dist/index-y2uJSngh.d.mts +60 -0
- package/dist/index-y2uJSngh.d.ts +60 -0
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/scoring-entry/index.d.mts +23 -0
- package/dist/scoring-entry/index.d.ts +23 -0
- package/dist/scoring-entry/index.js +133 -0
- package/dist/scoring-entry/index.mjs +6 -0
- package/dist/scoring-entry.d.mts +1 -1
- package/dist/scoring-entry.d.ts +1 -1
- package/dist/types-C4lmb2Yh.d.mts +36 -0
- package/dist/types-C4lmb2Yh.d.ts +36 -0
- package/package.json +16 -16
|
@@ -1,3 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
|
|
1
|
+
import { Severity, ScanOptions, AnalysisResult } from '@aiready/core';
|
|
2
|
+
import { P as PatternType, a as DuplicatePattern } from './types-C4lmb2Yh.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
|
+
interface PatternDetectOptions extends ScanOptions {
|
|
35
|
+
minSimilarity?: number;
|
|
36
|
+
minLines?: number;
|
|
37
|
+
batchSize?: number;
|
|
38
|
+
approx?: boolean;
|
|
39
|
+
minSharedTokens?: number;
|
|
40
|
+
maxCandidatesPerBlock?: number;
|
|
41
|
+
streamResults?: boolean;
|
|
42
|
+
severity?: string;
|
|
43
|
+
includeTests?: boolean;
|
|
44
|
+
useSmartDefaults?: boolean;
|
|
45
|
+
groupByFilePair?: boolean;
|
|
46
|
+
createClusters?: boolean;
|
|
47
|
+
minClusterTokenCost?: number;
|
|
48
|
+
minClusterFiles?: number;
|
|
49
|
+
excludePatterns?: string[];
|
|
50
|
+
confidenceThreshold?: number;
|
|
51
|
+
ignoreWhitelist?: string[];
|
|
52
|
+
onProgress?: (processed: number, total: number, message: string) => void;
|
|
53
|
+
}
|
|
54
|
+
interface PatternSummary {
|
|
55
|
+
totalPatterns: number;
|
|
56
|
+
totalTokenCost: number;
|
|
57
|
+
patternsByType: Record<PatternType, number>;
|
|
58
|
+
topDuplicates: Array<{
|
|
59
|
+
files: Array<{
|
|
60
|
+
path: string;
|
|
61
|
+
startLine: number;
|
|
62
|
+
endLine: number;
|
|
63
|
+
}>;
|
|
64
|
+
similarity: number;
|
|
65
|
+
patternType: PatternType;
|
|
66
|
+
tokenCost: number;
|
|
67
|
+
}>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Determine smart defaults based on repository size estimation.
|
|
71
|
+
*
|
|
72
|
+
* @param directory - The directory to analyze for size.
|
|
73
|
+
* @param userOptions - User-provided option overrides.
|
|
74
|
+
* @returns Promise resolving to optimal detection options.
|
|
75
|
+
*/
|
|
76
|
+
declare function getSmartDefaults(directory: string, userOptions: Partial<PatternDetectOptions>): Promise<PatternDetectOptions>;
|
|
77
|
+
/**
|
|
78
|
+
* Main entry point for pattern detection analysis.
|
|
79
|
+
*
|
|
80
|
+
* @param options - Configuration including rootDir and detection parameters.
|
|
81
|
+
* @returns Promise resolving to the comprehensive pattern detect report.
|
|
82
|
+
* @lastUpdated 2026-03-18
|
|
83
|
+
*/
|
|
84
|
+
declare function analyzePatterns(options: PatternDetectOptions): Promise<{
|
|
85
|
+
results: AnalysisResult[];
|
|
86
|
+
duplicates: DuplicatePattern[];
|
|
87
|
+
files: string[];
|
|
88
|
+
groups?: DuplicateGroup[];
|
|
89
|
+
clusters?: RefactorCluster[];
|
|
90
|
+
config: PatternDetectOptions;
|
|
91
|
+
}>;
|
|
92
|
+
/**
|
|
93
|
+
* Generate a summary of pattern detection results.
|
|
94
|
+
*
|
|
95
|
+
* @param results - Array of file-level analysis results.
|
|
96
|
+
* @returns Consolidated pattern summary object.
|
|
97
|
+
*/
|
|
98
|
+
declare function generateSummary(results: AnalysisResult[]): PatternSummary;
|
|
99
|
+
|
|
100
|
+
export { type PatternDetectOptions, type PatternSummary, analyzePatterns, generateSummary, getSmartDefaults };
|
package/dist/analyzer-entry.d.ts
CHANGED
|
@@ -1,3 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
import '
|
|
3
|
-
|
|
1
|
+
import { Severity, ScanOptions, AnalysisResult } from '@aiready/core';
|
|
2
|
+
import { P as PatternType, a as DuplicatePattern } from './types-C4lmb2Yh.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
|
+
interface PatternDetectOptions extends ScanOptions {
|
|
35
|
+
minSimilarity?: number;
|
|
36
|
+
minLines?: number;
|
|
37
|
+
batchSize?: number;
|
|
38
|
+
approx?: boolean;
|
|
39
|
+
minSharedTokens?: number;
|
|
40
|
+
maxCandidatesPerBlock?: number;
|
|
41
|
+
streamResults?: boolean;
|
|
42
|
+
severity?: string;
|
|
43
|
+
includeTests?: boolean;
|
|
44
|
+
useSmartDefaults?: boolean;
|
|
45
|
+
groupByFilePair?: boolean;
|
|
46
|
+
createClusters?: boolean;
|
|
47
|
+
minClusterTokenCost?: number;
|
|
48
|
+
minClusterFiles?: number;
|
|
49
|
+
excludePatterns?: string[];
|
|
50
|
+
confidenceThreshold?: number;
|
|
51
|
+
ignoreWhitelist?: string[];
|
|
52
|
+
onProgress?: (processed: number, total: number, message: string) => void;
|
|
53
|
+
}
|
|
54
|
+
interface PatternSummary {
|
|
55
|
+
totalPatterns: number;
|
|
56
|
+
totalTokenCost: number;
|
|
57
|
+
patternsByType: Record<PatternType, number>;
|
|
58
|
+
topDuplicates: Array<{
|
|
59
|
+
files: Array<{
|
|
60
|
+
path: string;
|
|
61
|
+
startLine: number;
|
|
62
|
+
endLine: number;
|
|
63
|
+
}>;
|
|
64
|
+
similarity: number;
|
|
65
|
+
patternType: PatternType;
|
|
66
|
+
tokenCost: number;
|
|
67
|
+
}>;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Determine smart defaults based on repository size estimation.
|
|
71
|
+
*
|
|
72
|
+
* @param directory - The directory to analyze for size.
|
|
73
|
+
* @param userOptions - User-provided option overrides.
|
|
74
|
+
* @returns Promise resolving to optimal detection options.
|
|
75
|
+
*/
|
|
76
|
+
declare function getSmartDefaults(directory: string, userOptions: Partial<PatternDetectOptions>): Promise<PatternDetectOptions>;
|
|
77
|
+
/**
|
|
78
|
+
* Main entry point for pattern detection analysis.
|
|
79
|
+
*
|
|
80
|
+
* @param options - Configuration including rootDir and detection parameters.
|
|
81
|
+
* @returns Promise resolving to the comprehensive pattern detect report.
|
|
82
|
+
* @lastUpdated 2026-03-18
|
|
83
|
+
*/
|
|
84
|
+
declare function analyzePatterns(options: PatternDetectOptions): Promise<{
|
|
85
|
+
results: AnalysisResult[];
|
|
86
|
+
duplicates: DuplicatePattern[];
|
|
87
|
+
files: string[];
|
|
88
|
+
groups?: DuplicateGroup[];
|
|
89
|
+
clusters?: RefactorCluster[];
|
|
90
|
+
config: PatternDetectOptions;
|
|
91
|
+
}>;
|
|
92
|
+
/**
|
|
93
|
+
* Generate a summary of pattern detection results.
|
|
94
|
+
*
|
|
95
|
+
* @param results - Array of file-level analysis results.
|
|
96
|
+
* @returns Consolidated pattern summary object.
|
|
97
|
+
*/
|
|
98
|
+
declare function generateSummary(results: AnalysisResult[]): PatternSummary;
|
|
99
|
+
|
|
100
|
+
export { type PatternDetectOptions, type PatternSummary, analyzePatterns, generateSummary, getSmartDefaults };
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/context-rules-entry/index.ts
|
|
21
|
+
var context_rules_entry_exports = {};
|
|
22
|
+
__export(context_rules_entry_exports, {
|
|
23
|
+
calculateSeverity: () => calculateSeverity,
|
|
24
|
+
filterBySeverity: () => filterBySeverity,
|
|
25
|
+
getSeverityLabel: () => getSeverityLabel,
|
|
26
|
+
getSeverityThreshold: () => getSeverityThreshold
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(context_rules_entry_exports);
|
|
29
|
+
|
|
30
|
+
// src/context-rules.ts
|
|
31
|
+
var import_core = require("@aiready/core");
|
|
32
|
+
var CONTEXT_RULES = [
|
|
33
|
+
// Test Fixtures - Intentional duplication for test isolation
|
|
34
|
+
{
|
|
35
|
+
name: "test-fixtures",
|
|
36
|
+
detect: (file, code) => {
|
|
37
|
+
const isTestFile = file.includes(".test.") || file.includes(".spec.") || file.includes("__tests__") || file.includes("/test/") || file.includes("/tests/");
|
|
38
|
+
const hasTestFixtures = code.includes("beforeAll") || code.includes("afterAll") || code.includes("beforeEach") || code.includes("afterEach") || code.includes("setUp") || code.includes("tearDown");
|
|
39
|
+
return isTestFile && hasTestFixtures;
|
|
40
|
+
},
|
|
41
|
+
severity: import_core.Severity.Info,
|
|
42
|
+
reason: "Test fixture duplication is intentional for test isolation",
|
|
43
|
+
suggestion: "Consider if shared test setup would improve maintainability without coupling tests"
|
|
44
|
+
},
|
|
45
|
+
// Email/Document Templates - Often intentionally similar for consistency
|
|
46
|
+
{
|
|
47
|
+
name: "templates",
|
|
48
|
+
detect: (file, code) => {
|
|
49
|
+
const isTemplate = file.includes("/templates/") || file.includes("-template") || file.includes("/email-templates/") || file.includes("/emails/");
|
|
50
|
+
const hasTemplateContent = (code.includes("return") || code.includes("export")) && (code.includes("html") || code.includes("subject") || code.includes("body"));
|
|
51
|
+
return isTemplate && hasTemplateContent;
|
|
52
|
+
},
|
|
53
|
+
severity: import_core.Severity.Minor,
|
|
54
|
+
reason: "Template duplication may be intentional for maintainability and branding consistency",
|
|
55
|
+
suggestion: "Extract shared structure only if templates become hard to maintain"
|
|
56
|
+
},
|
|
57
|
+
// E2E/Integration Test Page Objects - Test independence
|
|
58
|
+
{
|
|
59
|
+
name: "e2e-page-objects",
|
|
60
|
+
detect: (file, code) => {
|
|
61
|
+
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/");
|
|
62
|
+
const hasPageObjectPatterns = code.includes("page.") || code.includes("await page") || code.includes("locator") || code.includes("getBy") || code.includes("selector") || code.includes("click(") || code.includes("fill(");
|
|
63
|
+
return isE2ETest && hasPageObjectPatterns;
|
|
64
|
+
},
|
|
65
|
+
severity: import_core.Severity.Minor,
|
|
66
|
+
reason: "E2E test duplication ensures test independence and reduces coupling",
|
|
67
|
+
suggestion: "Consider page object pattern only if duplication causes maintenance issues"
|
|
68
|
+
},
|
|
69
|
+
// Configuration Files - Often necessarily similar by design
|
|
70
|
+
{
|
|
71
|
+
name: "config-files",
|
|
72
|
+
detect: (file) => {
|
|
73
|
+
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");
|
|
74
|
+
},
|
|
75
|
+
severity: import_core.Severity.Minor,
|
|
76
|
+
reason: "Configuration files often have similar structure by design",
|
|
77
|
+
suggestion: "Consider shared config base only if configurations become hard to maintain"
|
|
78
|
+
},
|
|
79
|
+
// Type Definitions - Duplication for type safety and module independence
|
|
80
|
+
{
|
|
81
|
+
name: "type-definitions",
|
|
82
|
+
detect: (file, code) => {
|
|
83
|
+
const isTypeFile = file.endsWith(".d.ts") || file.includes("/types/");
|
|
84
|
+
const hasTypeDefinitions = code.includes("interface ") || code.includes("type ") || code.includes("enum ");
|
|
85
|
+
return isTypeFile && hasTypeDefinitions;
|
|
86
|
+
},
|
|
87
|
+
severity: import_core.Severity.Info,
|
|
88
|
+
reason: "Type duplication may be intentional for module independence and type safety",
|
|
89
|
+
suggestion: "Extract to shared types package only if causing maintenance burden"
|
|
90
|
+
},
|
|
91
|
+
// Migration Scripts - One-off scripts that are similar by nature
|
|
92
|
+
{
|
|
93
|
+
name: "migration-scripts",
|
|
94
|
+
detect: (file) => {
|
|
95
|
+
return file.includes("/migrations/") || file.includes("/migrate/") || file.includes(".migration.");
|
|
96
|
+
},
|
|
97
|
+
severity: import_core.Severity.Info,
|
|
98
|
+
reason: "Migration scripts are typically one-off and intentionally similar",
|
|
99
|
+
suggestion: "Duplication is acceptable for migration scripts"
|
|
100
|
+
},
|
|
101
|
+
// Mock Data - Test data intentionally duplicated
|
|
102
|
+
{
|
|
103
|
+
name: "mock-data",
|
|
104
|
+
detect: (file, code) => {
|
|
105
|
+
const isMockFile = file.includes("/mocks/") || file.includes("/__mocks__/") || file.includes("/fixtures/") || file.includes(".mock.") || file.includes(".fixture.");
|
|
106
|
+
const hasMockData = code.includes("mock") || code.includes("Mock") || code.includes("fixture") || code.includes("stub") || code.includes("export const");
|
|
107
|
+
return isMockFile && hasMockData;
|
|
108
|
+
},
|
|
109
|
+
severity: import_core.Severity.Info,
|
|
110
|
+
reason: "Mock data duplication is expected for comprehensive test coverage",
|
|
111
|
+
suggestion: "Consider shared factories only for complex mock generation"
|
|
112
|
+
},
|
|
113
|
+
// Tool Implementations - Structural Boilerplate
|
|
114
|
+
{
|
|
115
|
+
name: "tool-implementations",
|
|
116
|
+
detect: (file, code) => {
|
|
117
|
+
const isToolFile = file.includes("/tools/") || file.endsWith(".tool.ts") || code.includes("toolDefinitions");
|
|
118
|
+
const hasToolStructure = code.includes("execute") && (code.includes("try") || code.includes("catch"));
|
|
119
|
+
return isToolFile && hasToolStructure;
|
|
120
|
+
},
|
|
121
|
+
severity: import_core.Severity.Info,
|
|
122
|
+
reason: "Tool implementations share structural boilerplate but have distinct business logic",
|
|
123
|
+
suggestion: "Tool duplication is acceptable for boilerplate interface wrappers"
|
|
124
|
+
}
|
|
125
|
+
];
|
|
126
|
+
function calculateSeverity(file1, file2, code, similarity, linesOfCode) {
|
|
127
|
+
for (const rule of CONTEXT_RULES) {
|
|
128
|
+
if (rule.detect(file1, code) || rule.detect(file2, code)) {
|
|
129
|
+
return {
|
|
130
|
+
severity: rule.severity,
|
|
131
|
+
reason: rule.reason,
|
|
132
|
+
suggestion: rule.suggestion,
|
|
133
|
+
matchedRule: rule.name
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (similarity >= 0.95 && linesOfCode >= 30) {
|
|
138
|
+
return {
|
|
139
|
+
severity: import_core.Severity.Critical,
|
|
140
|
+
reason: "Large nearly-identical code blocks waste tokens and create maintenance burden",
|
|
141
|
+
suggestion: "Extract to shared utility module immediately"
|
|
142
|
+
};
|
|
143
|
+
} else if (similarity >= 0.95 && linesOfCode >= 15) {
|
|
144
|
+
return {
|
|
145
|
+
severity: import_core.Severity.Major,
|
|
146
|
+
reason: "Nearly identical code should be consolidated",
|
|
147
|
+
suggestion: "Move to shared utility file"
|
|
148
|
+
};
|
|
149
|
+
} else if (similarity >= 0.85) {
|
|
150
|
+
return {
|
|
151
|
+
severity: import_core.Severity.Major,
|
|
152
|
+
reason: "High similarity indicates significant duplication",
|
|
153
|
+
suggestion: "Extract common logic to shared function"
|
|
154
|
+
};
|
|
155
|
+
} else if (similarity >= 0.7) {
|
|
156
|
+
return {
|
|
157
|
+
severity: import_core.Severity.Minor,
|
|
158
|
+
reason: "Moderate similarity detected",
|
|
159
|
+
suggestion: "Consider extracting shared patterns if code evolves together"
|
|
160
|
+
};
|
|
161
|
+
} else {
|
|
162
|
+
return {
|
|
163
|
+
severity: import_core.Severity.Minor,
|
|
164
|
+
reason: "Minor similarity detected",
|
|
165
|
+
suggestion: "Monitor but refactoring may not be worthwhile"
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
function getSeverityLabel(severity) {
|
|
170
|
+
const labels = {
|
|
171
|
+
[import_core.Severity.Critical]: "\u{1F534} CRITICAL",
|
|
172
|
+
[import_core.Severity.Major]: "\u{1F7E1} MAJOR",
|
|
173
|
+
[import_core.Severity.Minor]: "\u{1F535} MINOR",
|
|
174
|
+
[import_core.Severity.Info]: "\u2139\uFE0F INFO"
|
|
175
|
+
};
|
|
176
|
+
return labels[severity];
|
|
177
|
+
}
|
|
178
|
+
function filterBySeverity(duplicates, minSeverity) {
|
|
179
|
+
const severityOrder = [
|
|
180
|
+
import_core.Severity.Info,
|
|
181
|
+
import_core.Severity.Minor,
|
|
182
|
+
import_core.Severity.Major,
|
|
183
|
+
import_core.Severity.Critical
|
|
184
|
+
];
|
|
185
|
+
const minIndex = severityOrder.indexOf(minSeverity);
|
|
186
|
+
if (minIndex === -1) return duplicates;
|
|
187
|
+
return duplicates.filter((dup) => {
|
|
188
|
+
const dupIndex = severityOrder.indexOf(dup.severity);
|
|
189
|
+
return dupIndex >= minIndex;
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
function getSeverityThreshold(severity) {
|
|
193
|
+
const thresholds = {
|
|
194
|
+
[import_core.Severity.Critical]: 0.95,
|
|
195
|
+
[import_core.Severity.Major]: 0.85,
|
|
196
|
+
[import_core.Severity.Minor]: 0.5,
|
|
197
|
+
[import_core.Severity.Info]: 0
|
|
198
|
+
};
|
|
199
|
+
return thresholds[severity] || 0;
|
|
200
|
+
}
|
|
201
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
202
|
+
0 && (module.exports = {
|
|
203
|
+
calculateSeverity,
|
|
204
|
+
filterBySeverity,
|
|
205
|
+
getSeverityLabel,
|
|
206
|
+
getSeverityThreshold
|
|
207
|
+
});
|
|
@@ -1,2 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Severity } from '@aiready/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Context-aware severity detection for duplicate patterns
|
|
5
|
+
* Identifies intentional duplication patterns and adjusts severity accordingly
|
|
6
|
+
*/
|
|
7
|
+
interface ContextRule {
|
|
8
|
+
name: string;
|
|
9
|
+
detect: (file: string, code: string) => boolean;
|
|
10
|
+
severity: Severity;
|
|
11
|
+
reason: string;
|
|
12
|
+
suggestion?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Calculate severity based on context rules and code characteristics
|
|
16
|
+
*
|
|
17
|
+
* @param file1 - First file path in the duplicate pair.
|
|
18
|
+
* @param file2 - Second file path in the duplicate pair.
|
|
19
|
+
* @param code - Snippet of the duplicated code.
|
|
20
|
+
* @param similarity - The calculated similarity score (0-1).
|
|
21
|
+
* @param linesOfCode - Number of lines in the duplicated block.
|
|
22
|
+
* @returns An object containing the severity level and reasoning.
|
|
23
|
+
*/
|
|
24
|
+
declare function calculateSeverity(file1: string, file2: string, code: string, similarity: number, linesOfCode: number): {
|
|
25
|
+
severity: Severity;
|
|
26
|
+
reason?: string;
|
|
27
|
+
suggestion?: string;
|
|
28
|
+
matchedRule?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Get a human-readable severity label with emoji
|
|
32
|
+
*
|
|
33
|
+
* @param severity - The severity level to label.
|
|
34
|
+
* @returns Formatted label string for UI display.
|
|
35
|
+
*/
|
|
36
|
+
declare function getSeverityLabel(severity: Severity): string;
|
|
37
|
+
/**
|
|
38
|
+
* Filter duplicates by minimum severity threshold
|
|
39
|
+
*
|
|
40
|
+
* @param duplicates - List of items with a severity property.
|
|
41
|
+
* @param minSeverity - Minimum threshold for inclusion.
|
|
42
|
+
* @returns Filtered list of items.
|
|
43
|
+
*/
|
|
44
|
+
declare function filterBySeverity<T extends {
|
|
45
|
+
severity: Severity;
|
|
46
|
+
}>(duplicates: T[], minSeverity: Severity): T[];
|
|
47
|
+
/**
|
|
48
|
+
* Get numerical similarity threshold associated with a severity level
|
|
49
|
+
*
|
|
50
|
+
* @param severity - The severity level to look up.
|
|
51
|
+
* @returns Minimum similarity value for this severity.
|
|
52
|
+
*/
|
|
53
|
+
declare function getSeverityThreshold(severity: Severity): number;
|
|
54
|
+
|
|
55
|
+
export { type ContextRule, calculateSeverity, filterBySeverity, getSeverityLabel, getSeverityThreshold };
|
|
@@ -1,2 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Severity } from '@aiready/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Context-aware severity detection for duplicate patterns
|
|
5
|
+
* Identifies intentional duplication patterns and adjusts severity accordingly
|
|
6
|
+
*/
|
|
7
|
+
interface ContextRule {
|
|
8
|
+
name: string;
|
|
9
|
+
detect: (file: string, code: string) => boolean;
|
|
10
|
+
severity: Severity;
|
|
11
|
+
reason: string;
|
|
12
|
+
suggestion?: string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Calculate severity based on context rules and code characteristics
|
|
16
|
+
*
|
|
17
|
+
* @param file1 - First file path in the duplicate pair.
|
|
18
|
+
* @param file2 - Second file path in the duplicate pair.
|
|
19
|
+
* @param code - Snippet of the duplicated code.
|
|
20
|
+
* @param similarity - The calculated similarity score (0-1).
|
|
21
|
+
* @param linesOfCode - Number of lines in the duplicated block.
|
|
22
|
+
* @returns An object containing the severity level and reasoning.
|
|
23
|
+
*/
|
|
24
|
+
declare function calculateSeverity(file1: string, file2: string, code: string, similarity: number, linesOfCode: number): {
|
|
25
|
+
severity: Severity;
|
|
26
|
+
reason?: string;
|
|
27
|
+
suggestion?: string;
|
|
28
|
+
matchedRule?: string;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Get a human-readable severity label with emoji
|
|
32
|
+
*
|
|
33
|
+
* @param severity - The severity level to label.
|
|
34
|
+
* @returns Formatted label string for UI display.
|
|
35
|
+
*/
|
|
36
|
+
declare function getSeverityLabel(severity: Severity): string;
|
|
37
|
+
/**
|
|
38
|
+
* Filter duplicates by minimum severity threshold
|
|
39
|
+
*
|
|
40
|
+
* @param duplicates - List of items with a severity property.
|
|
41
|
+
* @param minSeverity - Minimum threshold for inclusion.
|
|
42
|
+
* @returns Filtered list of items.
|
|
43
|
+
*/
|
|
44
|
+
declare function filterBySeverity<T extends {
|
|
45
|
+
severity: Severity;
|
|
46
|
+
}>(duplicates: T[], minSeverity: Severity): T[];
|
|
47
|
+
/**
|
|
48
|
+
* Get numerical similarity threshold associated with a severity level
|
|
49
|
+
*
|
|
50
|
+
* @param severity - The severity level to look up.
|
|
51
|
+
* @returns Minimum similarity value for this severity.
|
|
52
|
+
*/
|
|
53
|
+
declare function getSeverityThreshold(severity: Severity): number;
|
|
54
|
+
|
|
55
|
+
export { type ContextRule, calculateSeverity, filterBySeverity, getSeverityLabel, getSeverityThreshold };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { a as DetectionOptions, D as DuplicatePattern } from '../types-DU2mmhwb.mjs';
|
|
2
|
+
export { P as PatternType } from '../types-DU2mmhwb.mjs';
|
|
3
|
+
import { FileContent } from '@aiready/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Detect duplicate patterns across files
|
|
7
|
+
*
|
|
8
|
+
* @param fileContents - Array of file contents to analyze.
|
|
9
|
+
* @param options - Configuration for duplicate detection (thresholds, progress, etc).
|
|
10
|
+
* @returns Promise resolving to an array of detected duplicate patterns sorted by similarity.
|
|
11
|
+
*/
|
|
12
|
+
declare function detectDuplicatePatterns(fileContents: FileContent[], options: DetectionOptions): Promise<DuplicatePattern[]>;
|
|
13
|
+
|
|
14
|
+
export { DuplicatePattern, detectDuplicatePatterns };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { a as DetectionOptions, D as DuplicatePattern } from '../types-DU2mmhwb.js';
|
|
2
|
+
export { P as PatternType } from '../types-DU2mmhwb.js';
|
|
3
|
+
import { FileContent } from '@aiready/core';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Detect duplicate patterns across files
|
|
7
|
+
*
|
|
8
|
+
* @param fileContents - Array of file contents to analyze.
|
|
9
|
+
* @param options - Configuration for duplicate detection (thresholds, progress, etc).
|
|
10
|
+
* @returns Promise resolving to an array of detected duplicate patterns sorted by similarity.
|
|
11
|
+
*/
|
|
12
|
+
declare function detectDuplicatePatterns(fileContents: FileContent[], options: DetectionOptions): Promise<DuplicatePattern[]>;
|
|
13
|
+
|
|
14
|
+
export { DuplicatePattern, detectDuplicatePatterns };
|