@aiready/pattern-detect 0.9.4 → 0.9.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/chunk-HOS5Z2NC.mjs +669 -0
- package/dist/chunk-T2C6WS73.mjs +670 -0
- package/dist/cli.js +15 -17
- package/dist/cli.mjs +8 -10
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +10 -11
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -54,7 +54,7 @@ var CONTEXT_RULES = [
|
|
|
54
54
|
const hasTemplateContent = (code.includes("return") || code.includes("export")) && (code.includes("html") || code.includes("subject") || code.includes("body"));
|
|
55
55
|
return isTemplate && hasTemplateContent;
|
|
56
56
|
},
|
|
57
|
-
severity: "
|
|
57
|
+
severity: "minor",
|
|
58
58
|
reason: "Template duplication may be intentional for maintainability and branding consistency",
|
|
59
59
|
suggestion: "Extract shared structure only if templates become hard to maintain"
|
|
60
60
|
},
|
|
@@ -66,7 +66,7 @@ var CONTEXT_RULES = [
|
|
|
66
66
|
const hasPageObjectPatterns = code.includes("page.") || code.includes("await page") || code.includes("locator") || code.includes("getBy") || code.includes("selector") || code.includes("click(") || code.includes("fill(");
|
|
67
67
|
return isE2ETest && hasPageObjectPatterns;
|
|
68
68
|
},
|
|
69
|
-
severity: "
|
|
69
|
+
severity: "minor",
|
|
70
70
|
reason: "E2E test duplication ensures test independence and reduces coupling",
|
|
71
71
|
suggestion: "Consider page object pattern only if duplication causes maintenance issues"
|
|
72
72
|
},
|
|
@@ -76,7 +76,7 @@ var CONTEXT_RULES = [
|
|
|
76
76
|
detect: (file) => {
|
|
77
77
|
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");
|
|
78
78
|
},
|
|
79
|
-
severity: "
|
|
79
|
+
severity: "minor",
|
|
80
80
|
reason: "Configuration files often have similar structure by design",
|
|
81
81
|
suggestion: "Consider shared config base only if configurations become hard to maintain"
|
|
82
82
|
},
|
|
@@ -134,32 +134,32 @@ function calculateSeverity(file1, file2, code, similarity, linesOfCode) {
|
|
|
134
134
|
};
|
|
135
135
|
} else if (similarity >= 0.95 && linesOfCode >= 15) {
|
|
136
136
|
return {
|
|
137
|
-
severity: "
|
|
137
|
+
severity: "major",
|
|
138
138
|
reason: "Nearly identical code should be consolidated",
|
|
139
139
|
suggestion: "Move to shared utility file"
|
|
140
140
|
};
|
|
141
141
|
} else if (similarity >= 0.85) {
|
|
142
142
|
return {
|
|
143
|
-
severity: "
|
|
143
|
+
severity: "major",
|
|
144
144
|
reason: "High similarity indicates significant duplication",
|
|
145
145
|
suggestion: "Extract common logic to shared function"
|
|
146
146
|
};
|
|
147
147
|
} else if (similarity >= 0.7) {
|
|
148
148
|
return {
|
|
149
|
-
severity: "
|
|
149
|
+
severity: "minor",
|
|
150
150
|
reason: "Moderate similarity detected",
|
|
151
151
|
suggestion: "Consider extracting shared patterns if code evolves together"
|
|
152
152
|
};
|
|
153
153
|
} else {
|
|
154
154
|
return {
|
|
155
|
-
severity: "
|
|
155
|
+
severity: "minor",
|
|
156
156
|
reason: "Minor similarity detected",
|
|
157
157
|
suggestion: "Monitor but refactoring may not be worthwhile"
|
|
158
158
|
};
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
161
|
function filterBySeverity(duplicates, minSeverity) {
|
|
162
|
-
const severityOrder = ["info", "
|
|
162
|
+
const severityOrder = ["info", "minor", "major", "critical"];
|
|
163
163
|
const minIndex = severityOrder.indexOf(minSeverity);
|
|
164
164
|
if (minIndex === -1) return duplicates;
|
|
165
165
|
return duplicates.filter((dup) => {
|
|
@@ -683,7 +683,7 @@ var import_fs = require("fs");
|
|
|
683
683
|
var import_path = require("path");
|
|
684
684
|
var import_core3 = require("@aiready/core");
|
|
685
685
|
var program = new import_commander.Command();
|
|
686
|
-
program.name("aiready-patterns").description("Detect duplicate patterns in your codebase").version("0.1.0").addHelpText("after", "\nCONFIGURATION:\n Supports config files: aiready.json, aiready.config.json, .aiready.json, .aireadyrc.json, aiready.config.js, .aireadyrc.js\n CLI options override config file settings\n\nPARAMETER TUNING:\n If you get too few results: decrease --similarity, --min-lines, or --min-shared-tokens\n If analysis is too slow: increase --min-lines, --min-shared-tokens, or decrease --max-candidates\n If you get too many false positives: increase --similarity or --min-lines\n\nEXAMPLES:\n aiready-patterns . # Basic analysis with smart defaults\n aiready-patterns . --similarity 0.3 --min-lines 3 # More sensitive detection\n aiready-patterns . --max-candidates 50 --no-approx # Slower but more thorough\n aiready-patterns . --output json > report.json # JSON export").argument("<directory>", "Directory to analyze").option("-s, --similarity <number>", "Minimum similarity score (0-1). Lower = more results, higher = fewer but more accurate. Default: 0.4").option("-l, --min-lines <number>", "Minimum lines to consider. Lower = more results, higher = faster analysis. Default: 5").option("--batch-size <number>", "Batch size for comparisons. Higher = faster but more memory. Default: 100").option("--no-approx", "Disable approximate candidate selection. Slower but more thorough on small repos").option("--min-shared-tokens <number>", "Minimum shared tokens to consider a candidate. Higher = faster, fewer results. Default: 8").option("--max-candidates <number>", "Maximum candidates per block. Higher = more thorough but slower. Default: 100").option("--no-stream-results", "Disable incremental output (default: enabled)").option("--include <patterns>", "File patterns to include (comma-separated)").option("--exclude <patterns>", "File patterns to exclude (comma-separated)").option("--min-severity <level>", "Minimum severity to show: critical|
|
|
686
|
+
program.name("aiready-patterns").description("Detect duplicate patterns in your codebase").version("0.1.0").addHelpText("after", "\nCONFIGURATION:\n Supports config files: aiready.json, aiready.config.json, .aiready.json, .aireadyrc.json, aiready.config.js, .aireadyrc.js\n CLI options override config file settings\n\nPARAMETER TUNING:\n If you get too few results: decrease --similarity, --min-lines, or --min-shared-tokens\n If analysis is too slow: increase --min-lines, --min-shared-tokens, or decrease --max-candidates\n If you get too many false positives: increase --similarity or --min-lines\n\nEXAMPLES:\n aiready-patterns . # Basic analysis with smart defaults\n aiready-patterns . --similarity 0.3 --min-lines 3 # More sensitive detection\n aiready-patterns . --max-candidates 50 --no-approx # Slower but more thorough\n aiready-patterns . --output json > report.json # JSON export").argument("<directory>", "Directory to analyze").option("-s, --similarity <number>", "Minimum similarity score (0-1). Lower = more results, higher = fewer but more accurate. Default: 0.4").option("-l, --min-lines <number>", "Minimum lines to consider. Lower = more results, higher = faster analysis. Default: 5").option("--batch-size <number>", "Batch size for comparisons. Higher = faster but more memory. Default: 100").option("--no-approx", "Disable approximate candidate selection. Slower but more thorough on small repos").option("--min-shared-tokens <number>", "Minimum shared tokens to consider a candidate. Higher = faster, fewer results. Default: 8").option("--max-candidates <number>", "Maximum candidates per block. Higher = more thorough but slower. Default: 100").option("--no-stream-results", "Disable incremental output (default: enabled)").option("--include <patterns>", "File patterns to include (comma-separated)").option("--exclude <patterns>", "File patterns to exclude (comma-separated)").option("--min-severity <level>", "Minimum severity to show: critical|major|minor|info. Default: minor").option("--exclude-test-fixtures", "Exclude test fixture duplication (beforeAll/afterAll)").option("--exclude-templates", "Exclude template file duplication").option("--include-tests", "Include test files in analysis (excluded by default)").option("--max-results <number>", "Maximum number of results to show in console output. Default: 10").option(
|
|
687
687
|
"-o, --output <format>",
|
|
688
688
|
"Output format: console, json, html",
|
|
689
689
|
"console"
|
|
@@ -701,7 +701,7 @@ program.name("aiready-patterns").description("Detect duplicate patterns in your
|
|
|
701
701
|
streamResults: true,
|
|
702
702
|
include: void 0,
|
|
703
703
|
exclude: void 0,
|
|
704
|
-
minSeverity: "
|
|
704
|
+
minSeverity: "minor",
|
|
705
705
|
excludeTestFixtures: false,
|
|
706
706
|
excludeTemplates: false,
|
|
707
707
|
includeTests: false,
|
|
@@ -822,10 +822,9 @@ program.name("aiready-patterns").description("Detect duplicate patterns in your
|
|
|
822
822
|
console.log(import_chalk.default.bold.white(" TOP DUPLICATE PATTERNS"));
|
|
823
823
|
console.log(import_chalk.default.cyan(divider) + "\n");
|
|
824
824
|
const severityOrder = {
|
|
825
|
-
critical:
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
low: 2,
|
|
825
|
+
critical: 4,
|
|
826
|
+
major: 3,
|
|
827
|
+
minor: 2,
|
|
829
828
|
info: 1
|
|
830
829
|
};
|
|
831
830
|
const topDuplicates = filteredDuplicates.sort((a, b) => {
|
|
@@ -995,9 +994,8 @@ program.parse();
|
|
|
995
994
|
function getSeverityBadge(severity) {
|
|
996
995
|
const badges = {
|
|
997
996
|
critical: import_chalk.default.bgRed.white.bold(" CRITICAL "),
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
low: import_chalk.default.bgGray.white(" LOW "),
|
|
997
|
+
major: import_chalk.default.bgYellow.black.bold(" MAJOR "),
|
|
998
|
+
minor: import_chalk.default.bgBlue.white.bold(" MINOR "),
|
|
1001
999
|
info: import_chalk.default.bgCyan.black(" INFO ")
|
|
1002
1000
|
};
|
|
1003
1001
|
return badges[severity] || badges.info;
|
package/dist/cli.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
analyzePatterns,
|
|
4
4
|
filterBySeverity,
|
|
5
5
|
generateSummary
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-HOS5Z2NC.mjs";
|
|
7
7
|
|
|
8
8
|
// src/cli.ts
|
|
9
9
|
import { Command } from "commander";
|
|
@@ -12,7 +12,7 @@ import { writeFileSync, mkdirSync, existsSync } from "fs";
|
|
|
12
12
|
import { dirname } from "path";
|
|
13
13
|
import { loadConfig, mergeConfigWithDefaults, resolveOutputPath } from "@aiready/core";
|
|
14
14
|
var program = new Command();
|
|
15
|
-
program.name("aiready-patterns").description("Detect duplicate patterns in your codebase").version("0.1.0").addHelpText("after", "\nCONFIGURATION:\n Supports config files: aiready.json, aiready.config.json, .aiready.json, .aireadyrc.json, aiready.config.js, .aireadyrc.js\n CLI options override config file settings\n\nPARAMETER TUNING:\n If you get too few results: decrease --similarity, --min-lines, or --min-shared-tokens\n If analysis is too slow: increase --min-lines, --min-shared-tokens, or decrease --max-candidates\n If you get too many false positives: increase --similarity or --min-lines\n\nEXAMPLES:\n aiready-patterns . # Basic analysis with smart defaults\n aiready-patterns . --similarity 0.3 --min-lines 3 # More sensitive detection\n aiready-patterns . --max-candidates 50 --no-approx # Slower but more thorough\n aiready-patterns . --output json > report.json # JSON export").argument("<directory>", "Directory to analyze").option("-s, --similarity <number>", "Minimum similarity score (0-1). Lower = more results, higher = fewer but more accurate. Default: 0.4").option("-l, --min-lines <number>", "Minimum lines to consider. Lower = more results, higher = faster analysis. Default: 5").option("--batch-size <number>", "Batch size for comparisons. Higher = faster but more memory. Default: 100").option("--no-approx", "Disable approximate candidate selection. Slower but more thorough on small repos").option("--min-shared-tokens <number>", "Minimum shared tokens to consider a candidate. Higher = faster, fewer results. Default: 8").option("--max-candidates <number>", "Maximum candidates per block. Higher = more thorough but slower. Default: 100").option("--no-stream-results", "Disable incremental output (default: enabled)").option("--include <patterns>", "File patterns to include (comma-separated)").option("--exclude <patterns>", "File patterns to exclude (comma-separated)").option("--min-severity <level>", "Minimum severity to show: critical|
|
|
15
|
+
program.name("aiready-patterns").description("Detect duplicate patterns in your codebase").version("0.1.0").addHelpText("after", "\nCONFIGURATION:\n Supports config files: aiready.json, aiready.config.json, .aiready.json, .aireadyrc.json, aiready.config.js, .aireadyrc.js\n CLI options override config file settings\n\nPARAMETER TUNING:\n If you get too few results: decrease --similarity, --min-lines, or --min-shared-tokens\n If analysis is too slow: increase --min-lines, --min-shared-tokens, or decrease --max-candidates\n If you get too many false positives: increase --similarity or --min-lines\n\nEXAMPLES:\n aiready-patterns . # Basic analysis with smart defaults\n aiready-patterns . --similarity 0.3 --min-lines 3 # More sensitive detection\n aiready-patterns . --max-candidates 50 --no-approx # Slower but more thorough\n aiready-patterns . --output json > report.json # JSON export").argument("<directory>", "Directory to analyze").option("-s, --similarity <number>", "Minimum similarity score (0-1). Lower = more results, higher = fewer but more accurate. Default: 0.4").option("-l, --min-lines <number>", "Minimum lines to consider. Lower = more results, higher = faster analysis. Default: 5").option("--batch-size <number>", "Batch size for comparisons. Higher = faster but more memory. Default: 100").option("--no-approx", "Disable approximate candidate selection. Slower but more thorough on small repos").option("--min-shared-tokens <number>", "Minimum shared tokens to consider a candidate. Higher = faster, fewer results. Default: 8").option("--max-candidates <number>", "Maximum candidates per block. Higher = more thorough but slower. Default: 100").option("--no-stream-results", "Disable incremental output (default: enabled)").option("--include <patterns>", "File patterns to include (comma-separated)").option("--exclude <patterns>", "File patterns to exclude (comma-separated)").option("--min-severity <level>", "Minimum severity to show: critical|major|minor|info. Default: minor").option("--exclude-test-fixtures", "Exclude test fixture duplication (beforeAll/afterAll)").option("--exclude-templates", "Exclude template file duplication").option("--include-tests", "Include test files in analysis (excluded by default)").option("--max-results <number>", "Maximum number of results to show in console output. Default: 10").option(
|
|
16
16
|
"-o, --output <format>",
|
|
17
17
|
"Output format: console, json, html",
|
|
18
18
|
"console"
|
|
@@ -30,7 +30,7 @@ program.name("aiready-patterns").description("Detect duplicate patterns in your
|
|
|
30
30
|
streamResults: true,
|
|
31
31
|
include: void 0,
|
|
32
32
|
exclude: void 0,
|
|
33
|
-
minSeverity: "
|
|
33
|
+
minSeverity: "minor",
|
|
34
34
|
excludeTestFixtures: false,
|
|
35
35
|
excludeTemplates: false,
|
|
36
36
|
includeTests: false,
|
|
@@ -151,10 +151,9 @@ program.name("aiready-patterns").description("Detect duplicate patterns in your
|
|
|
151
151
|
console.log(chalk.bold.white(" TOP DUPLICATE PATTERNS"));
|
|
152
152
|
console.log(chalk.cyan(divider) + "\n");
|
|
153
153
|
const severityOrder = {
|
|
154
|
-
critical:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
low: 2,
|
|
154
|
+
critical: 4,
|
|
155
|
+
major: 3,
|
|
156
|
+
minor: 2,
|
|
158
157
|
info: 1
|
|
159
158
|
};
|
|
160
159
|
const topDuplicates = filteredDuplicates.sort((a, b) => {
|
|
@@ -324,9 +323,8 @@ program.parse();
|
|
|
324
323
|
function getSeverityBadge(severity) {
|
|
325
324
|
const badges = {
|
|
326
325
|
critical: chalk.bgRed.white.bold(" CRITICAL "),
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
low: chalk.bgGray.white(" LOW "),
|
|
326
|
+
major: chalk.bgYellow.black.bold(" MAJOR "),
|
|
327
|
+
minor: chalk.bgBlue.white.bold(" MINOR "),
|
|
330
328
|
info: chalk.bgCyan.black(" INFO ")
|
|
331
329
|
};
|
|
332
330
|
return badges[severity] || badges.info;
|
package/dist/index.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import { ScanOptions, AnalysisResult } from '@aiready/core';
|
|
|
4
4
|
* Context-aware severity detection for duplicate patterns
|
|
5
5
|
* Identifies intentional duplication patterns and adjusts severity accordingly
|
|
6
6
|
*/
|
|
7
|
-
type Severity = 'critical' | '
|
|
7
|
+
type Severity = 'critical' | 'major' | 'minor' | 'info';
|
|
8
8
|
/**
|
|
9
9
|
* Calculate severity based on context rules and code characteristics
|
|
10
10
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { ScanOptions, AnalysisResult } from '@aiready/core';
|
|
|
4
4
|
* Context-aware severity detection for duplicate patterns
|
|
5
5
|
* Identifies intentional duplication patterns and adjusts severity accordingly
|
|
6
6
|
*/
|
|
7
|
-
type Severity = 'critical' | '
|
|
7
|
+
type Severity = 'critical' | 'major' | 'minor' | 'info';
|
|
8
8
|
/**
|
|
9
9
|
* Calculate severity based on context rules and code characteristics
|
|
10
10
|
*/
|
package/dist/index.js
CHANGED
|
@@ -66,7 +66,7 @@ var CONTEXT_RULES = [
|
|
|
66
66
|
const hasTemplateContent = (code.includes("return") || code.includes("export")) && (code.includes("html") || code.includes("subject") || code.includes("body"));
|
|
67
67
|
return isTemplate && hasTemplateContent;
|
|
68
68
|
},
|
|
69
|
-
severity: "
|
|
69
|
+
severity: "minor",
|
|
70
70
|
reason: "Template duplication may be intentional for maintainability and branding consistency",
|
|
71
71
|
suggestion: "Extract shared structure only if templates become hard to maintain"
|
|
72
72
|
},
|
|
@@ -78,7 +78,7 @@ var CONTEXT_RULES = [
|
|
|
78
78
|
const hasPageObjectPatterns = code.includes("page.") || code.includes("await page") || code.includes("locator") || code.includes("getBy") || code.includes("selector") || code.includes("click(") || code.includes("fill(");
|
|
79
79
|
return isE2ETest && hasPageObjectPatterns;
|
|
80
80
|
},
|
|
81
|
-
severity: "
|
|
81
|
+
severity: "minor",
|
|
82
82
|
reason: "E2E test duplication ensures test independence and reduces coupling",
|
|
83
83
|
suggestion: "Consider page object pattern only if duplication causes maintenance issues"
|
|
84
84
|
},
|
|
@@ -88,7 +88,7 @@ var CONTEXT_RULES = [
|
|
|
88
88
|
detect: (file) => {
|
|
89
89
|
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");
|
|
90
90
|
},
|
|
91
|
-
severity: "
|
|
91
|
+
severity: "minor",
|
|
92
92
|
reason: "Configuration files often have similar structure by design",
|
|
93
93
|
suggestion: "Consider shared config base only if configurations become hard to maintain"
|
|
94
94
|
},
|
|
@@ -146,25 +146,25 @@ function calculateSeverity(file1, file2, code, similarity, linesOfCode) {
|
|
|
146
146
|
};
|
|
147
147
|
} else if (similarity >= 0.95 && linesOfCode >= 15) {
|
|
148
148
|
return {
|
|
149
|
-
severity: "
|
|
149
|
+
severity: "major",
|
|
150
150
|
reason: "Nearly identical code should be consolidated",
|
|
151
151
|
suggestion: "Move to shared utility file"
|
|
152
152
|
};
|
|
153
153
|
} else if (similarity >= 0.85) {
|
|
154
154
|
return {
|
|
155
|
-
severity: "
|
|
155
|
+
severity: "major",
|
|
156
156
|
reason: "High similarity indicates significant duplication",
|
|
157
157
|
suggestion: "Extract common logic to shared function"
|
|
158
158
|
};
|
|
159
159
|
} else if (similarity >= 0.7) {
|
|
160
160
|
return {
|
|
161
|
-
severity: "
|
|
161
|
+
severity: "minor",
|
|
162
162
|
reason: "Moderate similarity detected",
|
|
163
163
|
suggestion: "Consider extracting shared patterns if code evolves together"
|
|
164
164
|
};
|
|
165
165
|
} else {
|
|
166
166
|
return {
|
|
167
|
-
severity: "
|
|
167
|
+
severity: "minor",
|
|
168
168
|
reason: "Minor similarity detected",
|
|
169
169
|
suggestion: "Monitor but refactoring may not be worthwhile"
|
|
170
170
|
};
|
|
@@ -173,15 +173,14 @@ function calculateSeverity(file1, file2, code, similarity, linesOfCode) {
|
|
|
173
173
|
function getSeverityLabel(severity) {
|
|
174
174
|
const labels = {
|
|
175
175
|
critical: "\u{1F534} CRITICAL",
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
low: "\u26AA LOW",
|
|
176
|
+
major: "\u{1F7E1} MAJOR",
|
|
177
|
+
minor: "\u{1F535} MINOR",
|
|
179
178
|
info: "\u2139\uFE0F INFO"
|
|
180
179
|
};
|
|
181
180
|
return labels[severity];
|
|
182
181
|
}
|
|
183
182
|
function filterBySeverity(duplicates, minSeverity) {
|
|
184
|
-
const severityOrder = ["info", "
|
|
183
|
+
const severityOrder = ["info", "minor", "major", "critical"];
|
|
185
184
|
const minIndex = severityOrder.indexOf(minSeverity);
|
|
186
185
|
if (minIndex === -1) return duplicates;
|
|
187
186
|
return duplicates.filter((dup) => {
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiready/pattern-detect",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.6",
|
|
4
4
|
"description": "Semantic duplicate pattern detection for AI-generated code - finds similar implementations that waste AI context tokens",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|