@aiready/pattern-detect 0.10.0 → 0.11.0
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-7O2DUBSN.mjs +1058 -0
- package/dist/chunk-MJWBS6SM.mjs +1058 -0
- package/dist/chunk-PEEHSFDR.mjs +1058 -0
- package/dist/chunk-XJD35DS6.mjs +1058 -0
- package/dist/cli.js +9 -6
- package/dist/cli.mjs +1 -1
- package/dist/index.js +9 -6
- package/dist/index.mjs +1 -1
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -380,6 +380,9 @@ function extractCodeBlocks(content, minLines) {
|
|
|
380
380
|
return blocks;
|
|
381
381
|
}
|
|
382
382
|
function normalizeCode(code) {
|
|
383
|
+
if (!code) {
|
|
384
|
+
return "";
|
|
385
|
+
}
|
|
383
386
|
return code.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "").replace(/"[^"]*"/g, '"STR"').replace(/'[^']*'/g, "'STR'").replace(/`[^`]*`/g, "`STR`").replace(/\b\d+\b/g, "NUM").replace(/\s+/g, " ").trim();
|
|
384
387
|
}
|
|
385
388
|
function jaccardSimilarity(tokens1, tokens2) {
|
|
@@ -405,7 +408,7 @@ async function detectDuplicatePatterns(files, options) {
|
|
|
405
408
|
const duplicates = [];
|
|
406
409
|
const maxComparisons = approx ? Infinity : 5e5;
|
|
407
410
|
const allBlocks = files.flatMap(
|
|
408
|
-
(file) => extractCodeBlocks(file.content, minLines).map((block) => ({
|
|
411
|
+
(file) => extractCodeBlocks(file.content, minLines).filter((block) => block.content && block.content.trim().length > 0).map((block) => ({
|
|
409
412
|
content: block.content,
|
|
410
413
|
startLine: block.startLine,
|
|
411
414
|
endLine: block.endLine,
|
|
@@ -421,7 +424,7 @@ async function detectDuplicatePatterns(files, options) {
|
|
|
421
424
|
if (pythonFiles.length > 0) {
|
|
422
425
|
const { extractPythonPatterns: extractPythonPatterns2 } = await Promise.resolve().then(() => (init_python_extractor(), python_extractor_exports));
|
|
423
426
|
const patterns = await extractPythonPatterns2(pythonFiles.map((f) => f.file));
|
|
424
|
-
const pythonBlocks = patterns.map((p) => ({
|
|
427
|
+
const pythonBlocks = patterns.filter((p) => p.code && p.code.trim().length > 0).map((p) => ({
|
|
425
428
|
content: p.code,
|
|
426
429
|
startLine: p.startLine,
|
|
427
430
|
endLine: p.endLine,
|
|
@@ -815,10 +818,10 @@ function getHighestSeverity(severities) {
|
|
|
815
818
|
};
|
|
816
819
|
let highest = "info";
|
|
817
820
|
let highestValue = 0;
|
|
818
|
-
for (const
|
|
819
|
-
if (order[
|
|
820
|
-
highestValue = order[
|
|
821
|
-
highest =
|
|
821
|
+
for (const severity of severities) {
|
|
822
|
+
if (order[severity] > highestValue) {
|
|
823
|
+
highestValue = order[severity];
|
|
824
|
+
highest = severity;
|
|
822
825
|
}
|
|
823
826
|
}
|
|
824
827
|
return highest;
|
package/dist/cli.mjs
CHANGED
package/dist/index.js
CHANGED
|
@@ -398,6 +398,9 @@ function extractCodeBlocks(content, minLines) {
|
|
|
398
398
|
return blocks;
|
|
399
399
|
}
|
|
400
400
|
function normalizeCode(code) {
|
|
401
|
+
if (!code) {
|
|
402
|
+
return "";
|
|
403
|
+
}
|
|
401
404
|
return code.replace(/\/\/.*$/gm, "").replace(/\/\*[\s\S]*?\*\//g, "").replace(/"[^"]*"/g, '"STR"').replace(/'[^']*'/g, "'STR'").replace(/`[^`]*`/g, "`STR`").replace(/\b\d+\b/g, "NUM").replace(/\s+/g, " ").trim();
|
|
402
405
|
}
|
|
403
406
|
function jaccardSimilarity(tokens1, tokens2) {
|
|
@@ -423,7 +426,7 @@ async function detectDuplicatePatterns(files, options) {
|
|
|
423
426
|
const duplicates = [];
|
|
424
427
|
const maxComparisons = approx ? Infinity : 5e5;
|
|
425
428
|
const allBlocks = files.flatMap(
|
|
426
|
-
(file) => extractCodeBlocks(file.content, minLines).map((block) => ({
|
|
429
|
+
(file) => extractCodeBlocks(file.content, minLines).filter((block) => block.content && block.content.trim().length > 0).map((block) => ({
|
|
427
430
|
content: block.content,
|
|
428
431
|
startLine: block.startLine,
|
|
429
432
|
endLine: block.endLine,
|
|
@@ -439,7 +442,7 @@ async function detectDuplicatePatterns(files, options) {
|
|
|
439
442
|
if (pythonFiles.length > 0) {
|
|
440
443
|
const { extractPythonPatterns: extractPythonPatterns2 } = await Promise.resolve().then(() => (init_python_extractor(), python_extractor_exports));
|
|
441
444
|
const patterns = await extractPythonPatterns2(pythonFiles.map((f) => f.file));
|
|
442
|
-
const pythonBlocks = patterns.map((p) => ({
|
|
445
|
+
const pythonBlocks = patterns.filter((p) => p.code && p.code.trim().length > 0).map((p) => ({
|
|
443
446
|
content: p.code,
|
|
444
447
|
startLine: p.startLine,
|
|
445
448
|
endLine: p.endLine,
|
|
@@ -833,10 +836,10 @@ function getHighestSeverity(severities) {
|
|
|
833
836
|
};
|
|
834
837
|
let highest = "info";
|
|
835
838
|
let highestValue = 0;
|
|
836
|
-
for (const
|
|
837
|
-
if (order[
|
|
838
|
-
highestValue = order[
|
|
839
|
-
highest =
|
|
839
|
+
for (const severity of severities) {
|
|
840
|
+
if (order[severity] > highestValue) {
|
|
841
|
+
highestValue = order[severity];
|
|
842
|
+
highest = severity;
|
|
840
843
|
}
|
|
841
844
|
}
|
|
842
845
|
return highest;
|
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aiready/pattern-detect",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
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,11 +45,11 @@
|
|
|
45
45
|
"dependencies": {
|
|
46
46
|
"commander": "^14.0.0",
|
|
47
47
|
"chalk": "^5.3.0",
|
|
48
|
-
"@aiready/core": "0.
|
|
48
|
+
"@aiready/core": "0.9.0"
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"tsup": "^8.3.5",
|
|
52
|
-
"eslint": "^
|
|
52
|
+
"eslint": "^10.0.0"
|
|
53
53
|
},
|
|
54
54
|
"files": [
|
|
55
55
|
"dist",
|