# All files defaults.ts

0% Statements 0/22
0% Branches 0/8
0% Functions 0/1
0% Lines 0/22

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60

     import { scanFiles } from '@aiready/core';
    import type { ContextAnalyzerOptions } from './types';

    /**
     * Generate smart defaults for context analysis based on repository size
     * Automatically tunes thresholds to target ~10 most serious issues
     */
    export async function getSmartDefaults(
      directory: string,
      userOptions: Partial<ContextAnalyzerOptions>
    ): Promise<ContextAnalyzerOptions> {
      // Estimate repository size by scanning files
      const files = await scanFiles({
        rootDir: directory,
        include: userOptions.include,
        exclude: userOptions.exclude,
      });

      const estimatedBlocks = files.length;

      let maxDepth: number;
      let maxContextBudget: number;
      let minCohesion: number;
      let maxFragmentation: number;

      if (estimatedBlocks < 100) {
        maxDepth = 4;
        maxContextBudget = 8000;
        minCohesion = 0.5;
        maxFragmentation = 0.5;
      } else if (estimatedBlocks < 500) {
        maxDepth = 5;
        maxContextBudget = 15000;
        minCohesion = 0.45;
        maxFragmentation = 0.6;
      } else if (estimatedBlocks < 2000) {
        maxDepth = 7;
        maxContextBudget = 25000;
        minCohesion = 0.4;
        maxFragmentation = 0.7;
      } else {
        maxDepth = 10;
        maxContextBudget = 40000;
        minCohesion = 0.35;
        maxFragmentation = 0.8;
      }

      return {
        maxDepth,
        maxContextBudget,
        minCohesion,
        maxFragmentation,
        focus: 'all',
        includeNodeModules: false,
        rootDir: userOptions.rootDir || directory,
        include: userOptions.include,
        exclude: userOptions.exclude,
      };
    }