@aiready/pattern-detect 0.7.7 → 0.7.11
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/README.md +130 -0
- package/dist/chunk-262N2JB7.mjs +497 -0
- package/dist/chunk-GSJFORRO.mjs +504 -0
- package/dist/chunk-M4PQMW34.mjs +480 -0
- package/dist/chunk-R2S73CVG.mjs +503 -0
- package/dist/chunk-S2KQFII2.mjs +491 -0
- package/dist/chunk-TJKDLVLN.mjs +503 -0
- package/dist/cli.js +57 -48
- package/dist/cli.mjs +16 -2
- package/dist/index.d.mts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +46 -49
- package/dist/index.mjs +5 -3
- package/package.json +2 -2
package/dist/cli.mjs
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import {
|
|
3
3
|
analyzePatterns,
|
|
4
4
|
generateSummary
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-GSJFORRO.mjs";
|
|
6
6
|
|
|
7
7
|
// src/cli.ts
|
|
8
8
|
import { Command } from "commander";
|
|
@@ -11,7 +11,7 @@ import { writeFileSync } from "fs";
|
|
|
11
11
|
import { join } from "path";
|
|
12
12
|
import { loadConfig, mergeConfigWithDefaults } from "@aiready/core";
|
|
13
13
|
var program = new Command();
|
|
14
|
-
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").argument("<directory>", "Directory to analyze").option("-s, --similarity <number>", "Minimum similarity score (0-1)").option("-l, --min-lines <number>", "Minimum lines to consider").option("--batch-size <number>", "Batch size for comparisons").option("--no-approx", "Disable approximate candidate selection
|
|
14
|
+
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("--severity <level>", "Filter by severity: critical|high|medium|all. Default: all").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(
|
|
15
15
|
"-o, --output <format>",
|
|
16
16
|
"Output format: console, json, html",
|
|
17
17
|
"console"
|
|
@@ -163,6 +163,20 @@ program.name("aiready-patterns").description("Detect duplicate patterns in your
|
|
|
163
163
|
}
|
|
164
164
|
if (totalIssues === 0) {
|
|
165
165
|
console.log(chalk.green("\n\u2728 Great! No duplicate patterns detected.\n"));
|
|
166
|
+
console.log(chalk.yellow("\u{1F4A1} If you expected to find duplicates, try adjusting parameters:"));
|
|
167
|
+
console.log(chalk.dim(" \u2022 Lower similarity threshold: --similarity 0.3"));
|
|
168
|
+
console.log(chalk.dim(" \u2022 Reduce minimum lines: --min-lines 3"));
|
|
169
|
+
console.log(chalk.dim(" \u2022 Include test files: --include-tests"));
|
|
170
|
+
console.log(chalk.dim(" \u2022 Lower shared tokens threshold: --min-shared-tokens 5"));
|
|
171
|
+
console.log("");
|
|
172
|
+
}
|
|
173
|
+
if (totalIssues > 0 && totalIssues < 5) {
|
|
174
|
+
console.log(chalk.yellow("\n\u{1F4A1} Few results found. To find more duplicates, try:"));
|
|
175
|
+
console.log(chalk.dim(" \u2022 Lower similarity threshold: --similarity 0.3"));
|
|
176
|
+
console.log(chalk.dim(" \u2022 Reduce minimum lines: --min-lines 3"));
|
|
177
|
+
console.log(chalk.dim(" \u2022 Include test files: --include-tests"));
|
|
178
|
+
console.log(chalk.dim(" \u2022 Lower shared tokens threshold: --min-shared-tokens 5"));
|
|
179
|
+
console.log("");
|
|
166
180
|
}
|
|
167
181
|
console.log(chalk.cyan(divider));
|
|
168
182
|
if (totalIssues > 0) {
|
package/dist/index.d.mts
CHANGED
|
@@ -61,6 +61,10 @@ interface PatternSummary {
|
|
|
61
61
|
tokenCost: number;
|
|
62
62
|
}>;
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Determine smart defaults based on repository size estimation
|
|
66
|
+
*/
|
|
67
|
+
declare function getSmartDefaults(directory: string, userOptions: Partial<PatternDetectOptions>): Promise<PatternDetectOptions>;
|
|
64
68
|
declare function analyzePatterns(options: PatternDetectOptions): Promise<{
|
|
65
69
|
results: AnalysisResult[];
|
|
66
70
|
duplicates: DuplicatePattern[];
|
|
@@ -71,4 +75,4 @@ declare function analyzePatterns(options: PatternDetectOptions): Promise<{
|
|
|
71
75
|
*/
|
|
72
76
|
declare function generateSummary(results: AnalysisResult[]): PatternSummary;
|
|
73
77
|
|
|
74
|
-
export { type DuplicatePattern, type PatternDetectOptions, type PatternSummary, type PatternType, analyzePatterns, detectDuplicatePatterns, generateSummary };
|
|
78
|
+
export { type DuplicatePattern, type PatternDetectOptions, type PatternSummary, type PatternType, analyzePatterns, detectDuplicatePatterns, generateSummary, getSmartDefaults };
|
package/dist/index.d.ts
CHANGED
|
@@ -61,6 +61,10 @@ interface PatternSummary {
|
|
|
61
61
|
tokenCost: number;
|
|
62
62
|
}>;
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Determine smart defaults based on repository size estimation
|
|
66
|
+
*/
|
|
67
|
+
declare function getSmartDefaults(directory: string, userOptions: Partial<PatternDetectOptions>): Promise<PatternDetectOptions>;
|
|
64
68
|
declare function analyzePatterns(options: PatternDetectOptions): Promise<{
|
|
65
69
|
results: AnalysisResult[];
|
|
66
70
|
duplicates: DuplicatePattern[];
|
|
@@ -71,4 +75,4 @@ declare function analyzePatterns(options: PatternDetectOptions): Promise<{
|
|
|
71
75
|
*/
|
|
72
76
|
declare function generateSummary(results: AnalysisResult[]): PatternSummary;
|
|
73
77
|
|
|
74
|
-
export { type DuplicatePattern, type PatternDetectOptions, type PatternSummary, type PatternType, analyzePatterns, detectDuplicatePatterns, generateSummary };
|
|
78
|
+
export { type DuplicatePattern, type PatternDetectOptions, type PatternSummary, type PatternType, analyzePatterns, detectDuplicatePatterns, generateSummary, getSmartDefaults };
|
package/dist/index.js
CHANGED
|
@@ -32,7 +32,8 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
analyzePatterns: () => analyzePatterns,
|
|
34
34
|
detectDuplicatePatterns: () => detectDuplicatePatterns,
|
|
35
|
-
generateSummary: () => generateSummary
|
|
35
|
+
generateSummary: () => generateSummary,
|
|
36
|
+
getSmartDefaults: () => getSmartDefaults
|
|
36
37
|
});
|
|
37
38
|
module.exports = __toCommonJS(index_exports);
|
|
38
39
|
var import_core2 = require("@aiready/core");
|
|
@@ -220,7 +221,13 @@ async function detectDuplicatePatterns(files, options) {
|
|
|
220
221
|
let candidates = null;
|
|
221
222
|
if (approx) {
|
|
222
223
|
const counts = /* @__PURE__ */ new Map();
|
|
223
|
-
|
|
224
|
+
const block1Tokens = new Set(blockTokens[i]);
|
|
225
|
+
const block1Size = block1Tokens.size;
|
|
226
|
+
const rareTokens = blockTokens[i].filter((tok) => {
|
|
227
|
+
const blocksWithToken = invertedIndex.get(tok)?.length || 0;
|
|
228
|
+
return blocksWithToken < allBlocks.length * 0.1;
|
|
229
|
+
});
|
|
230
|
+
for (const tok of rareTokens) {
|
|
224
231
|
const ids = invertedIndex.get(tok);
|
|
225
232
|
if (!ids) continue;
|
|
226
233
|
for (const j of ids) {
|
|
@@ -229,7 +236,13 @@ async function detectDuplicatePatterns(files, options) {
|
|
|
229
236
|
counts.set(j, (counts.get(j) || 0) + 1);
|
|
230
237
|
}
|
|
231
238
|
}
|
|
232
|
-
candidates = Array.from(counts.entries()).filter(([
|
|
239
|
+
candidates = Array.from(counts.entries()).filter(([j, shared]) => {
|
|
240
|
+
const block2Tokens = blockTokens[j];
|
|
241
|
+
const block2Size = block2Tokens.length;
|
|
242
|
+
const minSize = Math.min(block1Size, block2Size);
|
|
243
|
+
const sharedPercentage = shared / minSize;
|
|
244
|
+
return shared >= minSharedTokens && sharedPercentage >= 0.3;
|
|
245
|
+
}).sort((a, b) => b[1] - a[1]).slice(0, Math.min(maxCandidatesPerBlock, 5)).map(([j, shared]) => ({ j, shared }));
|
|
233
246
|
}
|
|
234
247
|
if (approx && candidates) {
|
|
235
248
|
for (const { j } of candidates) {
|
|
@@ -322,12 +335,12 @@ async function getSmartDefaults(directory, userOptions) {
|
|
|
322
335
|
if (userOptions.useSmartDefaults === false) {
|
|
323
336
|
return {
|
|
324
337
|
rootDir: directory,
|
|
325
|
-
minSimilarity: 0.
|
|
326
|
-
minLines:
|
|
338
|
+
minSimilarity: 0.6,
|
|
339
|
+
minLines: 8,
|
|
327
340
|
batchSize: 100,
|
|
328
341
|
approx: true,
|
|
329
|
-
minSharedTokens:
|
|
330
|
-
maxCandidatesPerBlock:
|
|
342
|
+
minSharedTokens: 12,
|
|
343
|
+
maxCandidatesPerBlock: 5,
|
|
331
344
|
streamResults: false,
|
|
332
345
|
severity: "all",
|
|
333
346
|
includeTests: false
|
|
@@ -348,48 +361,31 @@ async function getSmartDefaults(directory, userOptions) {
|
|
|
348
361
|
const { scanFiles: scanFiles2 } = await import("@aiready/core");
|
|
349
362
|
const files = await scanFiles2(scanOptions);
|
|
350
363
|
const estimatedBlocks = files.length * 3;
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
streamResults: false,
|
|
375
|
-
severity: "all",
|
|
376
|
-
includeTests: false
|
|
377
|
-
};
|
|
378
|
-
} else {
|
|
379
|
-
defaults = {
|
|
380
|
-
rootDir: directory,
|
|
381
|
-
minSimilarity: 0.6,
|
|
382
|
-
minLines: 8,
|
|
383
|
-
batchSize: 200,
|
|
384
|
-
approx: true,
|
|
385
|
-
minSharedTokens: 12,
|
|
386
|
-
maxCandidatesPerBlock: 25,
|
|
387
|
-
streamResults: false,
|
|
388
|
-
severity: "high",
|
|
389
|
-
includeTests: false
|
|
390
|
-
};
|
|
364
|
+
const maxCandidatesPerBlock = Math.max(3, Math.min(10, Math.floor(3e4 / estimatedBlocks)));
|
|
365
|
+
const minSimilarity = Math.min(0.75, 0.5 + estimatedBlocks / 1e4 * 0.25);
|
|
366
|
+
const minLines = Math.max(6, Math.min(12, 6 + Math.floor(estimatedBlocks / 2e3)));
|
|
367
|
+
const minSharedTokens = Math.max(10, Math.min(20, 10 + Math.floor(estimatedBlocks / 2e3)));
|
|
368
|
+
const batchSize = estimatedBlocks > 1e3 ? 200 : 100;
|
|
369
|
+
const severity = estimatedBlocks > 5e3 ? "high" : "all";
|
|
370
|
+
let defaults = {
|
|
371
|
+
rootDir: directory,
|
|
372
|
+
minSimilarity,
|
|
373
|
+
minLines,
|
|
374
|
+
batchSize,
|
|
375
|
+
approx: true,
|
|
376
|
+
minSharedTokens,
|
|
377
|
+
maxCandidatesPerBlock,
|
|
378
|
+
streamResults: false,
|
|
379
|
+
severity,
|
|
380
|
+
includeTests: false
|
|
381
|
+
};
|
|
382
|
+
const result = { ...defaults };
|
|
383
|
+
for (const [key, value] of Object.entries(defaults)) {
|
|
384
|
+
if (key in userOptions && userOptions[key] !== void 0) {
|
|
385
|
+
result[key] = userOptions[key];
|
|
386
|
+
}
|
|
391
387
|
}
|
|
392
|
-
return
|
|
388
|
+
return result;
|
|
393
389
|
}
|
|
394
390
|
function logConfiguration(config, estimatedBlocks) {
|
|
395
391
|
console.log("\u{1F4CB} Configuration:");
|
|
@@ -540,5 +536,6 @@ function generateSummary(results) {
|
|
|
540
536
|
0 && (module.exports = {
|
|
541
537
|
analyzePatterns,
|
|
542
538
|
detectDuplicatePatterns,
|
|
543
|
-
generateSummary
|
|
539
|
+
generateSummary,
|
|
540
|
+
getSmartDefaults
|
|
544
541
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
analyzePatterns,
|
|
3
3
|
detectDuplicatePatterns,
|
|
4
|
-
generateSummary
|
|
5
|
-
|
|
4
|
+
generateSummary,
|
|
5
|
+
getSmartDefaults
|
|
6
|
+
} from "./chunk-GSJFORRO.mjs";
|
|
6
7
|
export {
|
|
7
8
|
analyzePatterns,
|
|
8
9
|
detectDuplicatePatterns,
|
|
9
|
-
generateSummary
|
|
10
|
+
generateSummary,
|
|
11
|
+
getSmartDefaults
|
|
10
12
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiready/pattern-detect",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.11",
|
|
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",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"commander": "^14.0.0",
|
|
47
47
|
"chalk": "^5.3.0",
|
|
48
|
-
"@aiready/core": "0.3.
|
|
48
|
+
"@aiready/core": "0.3.6"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"tsup": "^8.3.5",
|