@aiready/pattern-detect 0.7.6 → 0.7.9

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,79 @@ 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
+ const maxCandidatesPerBlock = Math.max(10, Math.min(100, Math.floor(8e4 / estimatedBlocks)));
352
+ const minSimilarity = Math.min(0.65, 0.4 + estimatedBlocks / 15e3 * 0.25);
353
+ const minLines = Math.max(5, Math.min(10, 5 + Math.floor(estimatedBlocks / 3e3)));
354
+ const minSharedTokens = Math.max(8, Math.min(15, 8 + Math.floor(estimatedBlocks / 4e3)));
355
+ const batchSize = estimatedBlocks > 2e3 ? 300 : 150;
356
+ const severity = estimatedBlocks > 8e3 ? "high" : "all";
357
+ let defaults = {
358
+ rootDir: directory,
359
+ minSimilarity,
360
+ minLines,
361
+ batchSize,
362
+ approx: true,
363
+ minSharedTokens,
364
+ maxCandidatesPerBlock,
365
+ streamResults: false,
366
+ severity,
367
+ includeTests: false
368
+ };
369
+ const result = { ...defaults };
370
+ for (const [key, value] of Object.entries(defaults)) {
371
+ if (key in userOptions && userOptions[key] !== void 0) {
372
+ result[key] = userOptions[key];
373
+ }
374
+ }
375
+ return result;
376
+ }
377
+ function logConfiguration(config, estimatedBlocks) {
378
+ console.log("\u{1F4CB} Configuration:");
379
+ console.log(` Repository size: ~${estimatedBlocks} code blocks`);
380
+ console.log(` Similarity threshold: ${config.minSimilarity}`);
381
+ console.log(` Minimum lines: ${config.minLines}`);
382
+ console.log(` Approximate mode: ${config.approx ? "enabled" : "disabled"}`);
383
+ console.log(` Max candidates per block: ${config.maxCandidatesPerBlock}`);
384
+ console.log(` Min shared tokens: ${config.minSharedTokens}`);
385
+ console.log(` Severity filter: ${config.severity}`);
386
+ console.log(` Include tests: ${config.includeTests}`);
387
+ console.log("");
388
+ }
311
389
  async function analyzePatterns(options) {
390
+ const smartDefaults = await getSmartDefaults(options.rootDir || ".", options);
391
+ const finalOptions = { ...smartDefaults, ...options };
312
392
  const {
313
393
  minSimilarity = 0.4,
314
- // Jaccard similarity default (40% threshold)
315
394
  minLines = 5,
316
395
  batchSize = 100,
317
396
  approx = true,
@@ -321,8 +400,11 @@ async function analyzePatterns(options) {
321
400
  severity = "all",
322
401
  includeTests = false,
323
402
  ...scanOptions
324
- } = options;
325
- const files = await (0, import_core2.scanFiles)(scanOptions);
403
+ } = finalOptions;
404
+ const { scanFiles: scanFiles2 } = await import("@aiready/core");
405
+ const files = await scanFiles2(scanOptions);
406
+ const estimatedBlocks = files.length * 3;
407
+ logConfiguration(finalOptions, estimatedBlocks);
326
408
  const results = [];
327
409
  const fileContents = await Promise.all(
328
410
  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-S2KQFII2.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.6",
3
+ "version": "0.7.9",
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.2"
48
+ "@aiready/core": "0.3.6"
49
49
  },
50
50
  "devDependencies": {
51
51
  "tsup": "^8.3.5",