@aiready/pattern-detect 0.7.5 → 0.7.7

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/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
@@ -308,10 +318,96 @@ function getRefactoringSuggestion(patternType, similarity) {
308
318
  const urgency = similarity > 0.95 ? " (CRITICAL: Nearly identical code)" : similarity > 0.9 ? " (HIGH: Very similar, refactor soon)" : "";
309
319
  return baseMessages[patternType] + urgency;
310
320
  }
321
+ async function getSmartDefaults(directory, userOptions) {
322
+ if (userOptions.useSmartDefaults === false) {
323
+ return {
324
+ rootDir: directory,
325
+ minSimilarity: 0.4,
326
+ minLines: 5,
327
+ batchSize: 100,
328
+ approx: true,
329
+ minSharedTokens: 8,
330
+ maxCandidatesPerBlock: 100,
331
+ streamResults: false,
332
+ severity: "all",
333
+ includeTests: false
334
+ };
335
+ }
336
+ const scanOptions = {
337
+ rootDir: directory,
338
+ include: userOptions.include || ["**/*.{ts,tsx,js,jsx,py,java}"],
339
+ exclude: userOptions.exclude || [
340
+ "**/node_modules/**",
341
+ "**/dist/**",
342
+ "**/build/**",
343
+ "**/coverage/**",
344
+ "**/.git/**",
345
+ "**/.turbo/**"
346
+ ]
347
+ };
348
+ const { scanFiles: scanFiles2 } = await import("@aiready/core");
349
+ const files = await scanFiles2(scanOptions);
350
+ const estimatedBlocks = files.length * 3;
351
+ let defaults;
352
+ if (estimatedBlocks < 1e3) {
353
+ defaults = {
354
+ rootDir: directory,
355
+ minSimilarity: 0.4,
356
+ minLines: 5,
357
+ batchSize: 100,
358
+ approx: true,
359
+ minSharedTokens: 8,
360
+ maxCandidatesPerBlock: 100,
361
+ streamResults: false,
362
+ severity: "all",
363
+ includeTests: false
364
+ };
365
+ } else if (estimatedBlocks < 5e3) {
366
+ defaults = {
367
+ rootDir: directory,
368
+ minSimilarity: 0.5,
369
+ minLines: 6,
370
+ batchSize: 100,
371
+ approx: true,
372
+ minSharedTokens: 10,
373
+ maxCandidatesPerBlock: 50,
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
+ };
391
+ }
392
+ return { ...defaults, ...scanOptions };
393
+ }
394
+ function logConfiguration(config, estimatedBlocks) {
395
+ console.log("\u{1F4CB} Configuration:");
396
+ console.log(` Repository size: ~${estimatedBlocks} code blocks`);
397
+ console.log(` Similarity threshold: ${config.minSimilarity}`);
398
+ console.log(` Minimum lines: ${config.minLines}`);
399
+ console.log(` Approximate mode: ${config.approx ? "enabled" : "disabled"}`);
400
+ console.log(` Max candidates per block: ${config.maxCandidatesPerBlock}`);
401
+ console.log(` Min shared tokens: ${config.minSharedTokens}`);
402
+ console.log(` Severity filter: ${config.severity}`);
403
+ console.log(` Include tests: ${config.includeTests}`);
404
+ console.log("");
405
+ }
311
406
  async function analyzePatterns(options) {
407
+ const smartDefaults = await getSmartDefaults(options.rootDir || ".", options);
408
+ const finalOptions = { ...smartDefaults, ...options };
312
409
  const {
313
410
  minSimilarity = 0.4,
314
- // Jaccard similarity default (40% threshold)
315
411
  minLines = 5,
316
412
  batchSize = 100,
317
413
  approx = true,
@@ -321,8 +417,11 @@ async function analyzePatterns(options) {
321
417
  severity = "all",
322
418
  includeTests = false,
323
419
  ...scanOptions
324
- } = options;
325
- const files = await (0, import_core2.scanFiles)(scanOptions);
420
+ } = finalOptions;
421
+ const { scanFiles: scanFiles2 } = await import("@aiready/core");
422
+ const files = await scanFiles2(scanOptions);
423
+ const estimatedBlocks = files.length * 3;
424
+ logConfiguration(finalOptions, estimatedBlocks);
326
425
  const results = [];
327
426
  const fileContents = await Promise.all(
328
427
  files.map(async (file) => ({
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@ import {
2
2
  analyzePatterns,
3
3
  detectDuplicatePatterns,
4
4
  generateSummary
5
- } from "./chunk-VRMXVYDZ.mjs";
5
+ } from "./chunk-YCGV65F5.mjs";
6
6
  export {
7
7
  analyzePatterns,
8
8
  detectDuplicatePatterns,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aiready/pattern-detect",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
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.1"
48
+ "@aiready/core": "0.3.3"
49
49
  },
50
50
  "devDependencies": {
51
51
  "tsup": "^8.3.5",