File size: 7,877 Bytes
a5489c7 | 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | "use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.resetFilterMetrics = exports.logTokenSavings = exports.logIgnoredFile = exports.filterMetrics = exports.generateIgnoredFileNotice = exports.isTotalDiffTooLarge = exports.isDiffTooLarge = exports.getFilePriority = exports.isGeneratedFile = exports.FILE_TYPE_PRIORITY = exports.DIFF_LIMITS = exports.GENERATED_FILE_PATTERNS = void 0;
exports.GENERATED_FILE_PATTERNS = [
// Dependency directories
'node_modules/',
'.next/',
'dist/',
'build/',
'coverage/',
'.turbo/',
'.cache/',
'.git/',
'.nuxt/',
'.output/',
'.vercel/',
'.netlify/',
'.serverless/',
// Lockfiles
'package-lock.json',
'yarn.lock',
'pnpm-lock.yaml',
'bun.lockb',
'composer.lock',
'Gemfile.lock',
'Cargo.lock',
'poetry.lock',
'requirements.txt',
'Pipfile.lock',
'go.sum',
// Minified files
'*.min.js',
'*.min.css',
'*.min.html',
// Source maps
'*.map',
'*.js.map',
'*.css.map',
// Logs
'*.log',
'npm-debug.log*',
'yarn-debug.log*',
'yarn-error.log*',
'pnpm-debug.log*',
// Generated directories
'vendor/',
'generated/',
'__generated__/',
'.generated/',
'out/',
'artifacts/',
'.artifact/',
// Test snapshots
'*.snap',
'*.snap.jsx',
'*.snap.tsx',
// Binary assets
'*.svg',
'*.png',
'*.jpg',
'*.jpeg',
'*.gif',
'*.webp',
'*.ico',
'*.bmp',
'*.tiff',
// Fonts
'*.woff',
'*.woff2',
'*.ttf',
'*.eot',
'*.otf',
// Other binary
'*.pdf',
'*.zip',
'*.tar',
'*.tar.gz',
'*.rar',
'*.7z',
// Build artifacts
'*.bundle.js',
'*.chunk.js',
'*.chunk.css',
// IDE
'.vscode/',
'.idea/',
'*.swp',
'*.swo',
'*~',
'.DS_Store',
'Thumbs.db',
// Environment
'.env',
'.env.*',
'*.env',
'.env.local',
'.env.development.local',
'.env.test.local',
'.env.production.local',
// CI/CD
'.github/workflows/*.log',
'.gitlab-ci.yml',
'Jenkinsfile',
'azure-pipelines.yml'
];
exports.DIFF_LIMITS = {
MAX_DIFF_CHARS: 4000,
MAX_TOTAL_DIFF_CHARS: 15000,
MAX_FILE_SIZE_CHARS: 100000
};
exports.FILE_TYPE_PRIORITY = {
// High priority - always analyze
HIGH: [
'.ts',
'.tsx',
'.js',
'.jsx',
'.py',
'.go',
'.rs',
'.java',
'.kt',
'.swift',
'.rb',
'.php',
'.cs',
'.cpp',
'.c',
'.h'
],
// Medium priority - analyze if relevant
MEDIUM: [
'.json',
'.yaml',
'.yml',
'.toml',
'.ini',
'.conf',
'.config',
'.xml'
],
// Low priority - skip unless explicitly needed
LOW: [
'.md',
'.txt',
'.svg',
'.png',
'.jpg',
'.jpeg',
'.gif',
'.webp',
'.ico',
'.woff',
'.woff2',
'.ttf',
'.eot'
]
};
const isGeneratedFile = (filePath) => {
const normalizedPath = filePath.replace(/\\/g, '/');
for (const pattern of exports.GENERATED_FILE_PATTERNS) {
if (pattern.includes('*')) {
// Glob pattern
const regexPattern = pattern.replace(/\./g, '\\.').replace(/\*/g, '.*');
const regex = new RegExp(regexPattern);
if (regex.test(normalizedPath)) {
return true;
}
}
else if (pattern.endsWith('/')) {
// Directory pattern
if (normalizedPath.startsWith(pattern) ||
normalizedPath.includes(`/${pattern}`)) {
return true;
}
}
else {
// Exact file pattern
if (normalizedPath === pattern ||
normalizedPath.endsWith(`/${pattern}`)) {
return true;
}
}
}
return false;
};
exports.isGeneratedFile = isGeneratedFile;
const getFilePriority = (filePath) => {
const ext = filePath.split('.').pop()?.toLowerCase();
if (!ext)
return 'medium';
const extWithDot = `.${ext}`;
if (exports.FILE_TYPE_PRIORITY.HIGH.includes(extWithDot))
return 'high';
if (exports.FILE_TYPE_PRIORITY.MEDIUM.includes(extWithDot))
return 'medium';
if (exports.FILE_TYPE_PRIORITY.LOW.includes(extWithDot))
return 'low';
return 'medium';
};
exports.getFilePriority = getFilePriority;
const isDiffTooLarge = (diff) => {
return diff.length > exports.DIFF_LIMITS.MAX_DIFF_CHARS;
};
exports.isDiffTooLarge = isDiffTooLarge;
const isTotalDiffTooLarge = (totalChars) => {
return totalChars > exports.DIFF_LIMITS.MAX_TOTAL_DIFF_CHARS;
};
exports.isTotalDiffTooLarge = isTotalDiffTooLarge;
const generateIgnoredFileNotice = (filePath) => {
const normalizedPath = filePath.replace(/\\/g, '/');
// Special handling for lockfiles
if (normalizedPath.includes('package-lock.json') ||
normalizedPath.includes('yarn.lock') ||
normalizedPath.includes('pnpm-lock.yaml') ||
normalizedPath.includes('bun.lockb')) {
return `⚠️ Generated dependency file skipped: ${filePath}
Large generated dependency files are excluded from AI review to reduce token usage and avoid noisy analysis.
Recommendation:
- Only commit lockfile changes when dependencies intentionally changed.
- Avoid unnecessary lockfile churn.
Suggested AI agent prompt:
"Review package.json changes and regenerate lockfile only if dependency versions were intentionally updated."`;
}
// Special handling for node_modules
if (normalizedPath.includes('node_modules/')) {
return `⚠️ Generated dependency directory skipped: ${filePath}
Generated dependencies are excluded from review and planning pipelines.`;
}
// Special handling for build artifacts
if (normalizedPath.includes('dist/') ||
normalizedPath.includes('build/') ||
normalizedPath.includes('.next/') ||
normalizedPath.includes('.nuxt/')) {
return `⚠️ Build artifact skipped: ${filePath}
Build output directories are excluded from AI review as they are generated from source code.`;
}
// Generic notice
return `⚠️ Generated file skipped: ${filePath}
This file matches generated file patterns and is excluded from AI review to reduce token usage.`;
};
exports.generateIgnoredFileNotice = generateIgnoredFileNotice;
exports.filterMetrics = {
ignoredFiles: [],
totalCharsSkipped: 0,
largestPreventedPayload: 0
};
const logIgnoredFile = (filePath, charsSkipped = 0) => {
console.log('IGNORED_GENERATED_FILE', { filePath, charsSkipped });
exports.filterMetrics.ignoredFiles.push(filePath);
exports.filterMetrics.totalCharsSkipped += charsSkipped;
exports.filterMetrics.largestPreventedPayload = Math.max(exports.filterMetrics.largestPreventedPayload, charsSkipped);
};
exports.logIgnoredFile = logIgnoredFile;
const logTokenSavings = () => {
const estimatedTokens = Math.round(exports.filterMetrics.totalCharsSkipped / 4); // Rough estimate: 4 chars per token
console.log('FILTERED_TOKEN_SAVINGS_ESTIMATE', {
filesSkipped: exports.filterMetrics.ignoredFiles.length,
charsSkipped: exports.filterMetrics.totalCharsSkipped,
estimatedTokens,
largestPreventedPayload: exports.filterMetrics.largestPreventedPayload
});
};
exports.logTokenSavings = logTokenSavings;
const resetFilterMetrics = () => {
exports.filterMetrics.ignoredFiles = [];
exports.filterMetrics.totalCharsSkipped = 0;
exports.filterMetrics.largestPreventedPayload = 0;
};
exports.resetFilterMetrics = resetFilterMetrics;
//# sourceMappingURL=generated-filter.js.map |