AI Pattern Detection
Vibesweep uses advanced pattern recognition to identify code likely generated by AI assistants like GitHub Copilot, ChatGPT, and other LLMs.
How It Works
Vibesweep analyzes code for telltale signs of AI generation:
- Pattern Matching - Identifies common AI code patterns
- Comment Analysis - Detects over-explanatory comments
- Structure Analysis - Recognizes verbose code structures
- Statistical Analysis - Calculates probability scores
AI Score
Each file receives an AI score from 0-100:
- 0-30: Human-written code
- 31-60: Mixed human/AI collaboration
- 61-80: Likely AI-generated
- 81-100: Definitely AI-generated
Detected Patterns
1. Verbose Conditionals
AI often generates unnecessarily verbose conditional checks:
// AI-generated (Score: +20)
if (user !== null && user !== undefined && user.id !== null && user.id !== undefined) {
// process user
}
// Human-optimized
if (user?.id) {
// process user
}
2. Redundant Comments
AI tends to over-comment obvious code:
// AI-generated (Score: +15)
// This function adds two numbers together and returns the result
function add(a, b) {
// Return the sum of a and b
return a + b;
}
// Human-written
function add(a, b) {
return a + b;
}
3. Boilerplate Excess
AI often includes unnecessary boilerplate:
// AI-generated (Score: +25)
class UserService {
constructor() {
// Initialize the user service
this.users = [];
}
// Method to get all users
getAllUsers() {
// Return all users
return this.users;
}
// Method to add a user
addUser(user) {
// Add user to the array
this.users.push(user);
// Return success
return true;
}
}
// Human-optimized
class UserService {
users = [];
getAllUsers = () => this.users;
addUser = (user) => this.users.push(user);
}
4. Ceremonial Code
Unnecessary ceremony and verbosity:
// AI-generated (Score: +30)
const processData = (data) => {
let result = null;
if (data) {
if (Array.isArray(data)) {
result = data.map(item => {
return processItem(item);
});
} else {
result = processItem(data);
}
}
return result;
};
// Human-optimized
const processData = (data) =>
Array.isArray(data) ? data.map(processItem) : processItem(data);
5. Debug Artifacts
Left-over console.logs and debug code:
// AI-generated (Score: +10)
function calculateTotal(items) {
console.log('Calculating total for items:', items);
const total = items.reduce((sum, item) => {
console.log('Processing item:', item);
return sum + item.price;
}, 0);
console.log('Total calculated:', total);
return total;
}
Pattern Categories
High Confidence Patterns (Score +20-30)
- Verbose null checking without optional chaining
- Redundant variable declarations
- Unnecessary else blocks after returns
- Over-engineered simple functions
Medium Confidence Patterns (Score +10-20)
- Excessive comments on obvious code
- Redundant return statements
- Unnecessary type conversions
- Verbose array/object operations
Low Confidence Patterns (Score +5-10)
- Multiple console.log statements
- TODO comments without context
- Generic variable names (data, result, temp)
- Inconsistent code style
Configuration
Custom Patterns
Add your own AI patterns in .vibesweeprc.json
:
{
"aiPatterns": {
"customPatterns": [
"// This function.*",
"// Helper function to.*",
"// Utility for.*",
"// Method to.*"
],
"ignorePatterns": [
"// Copyright.*",
"// @flow"
],
"scoreWeights": {
"verboseConditionals": 20,
"redundantComments": 15,
"boilerplateExcess": 25,
"debugArtifacts": 10
}
}
}
Threshold Settings
Control when files are flagged:
{
"thresholds": {
"maxAIScore": 70 // Flag files with AI score > 70
}
}
Best Practices
Working with AI Tools
- Review AI output - Always review and optimize generated code
- Remove comments - Delete obvious explanatory comments
- Simplify logic - Refactor verbose conditionals
- Clean artifacts - Remove debug console.logs
- Optimize structure - Simplify over-engineered solutions
Team Guidelines
Establish team standards for AI-assisted development:
## AI Code Standards
1. Maximum AI score: 50
2. Required optimizations:
- Use optional chaining
- Remove redundant comments
- Simplify conditionals
- Clean debug code
3. Code review checklist:
- [ ] AI score < 50
- [ ] No verbose patterns
- [ ] Comments add value
- [ ] No debug artifacts
Understanding Results
File Report
src/utils/validator.js
AI Score: 78/100
Patterns: verbose-conditionals, redundant-comments
Detected patterns:
- Line 12-18: Verbose null checking (use ?.)
- Line 25: Redundant comment "// Return the result"
- Line 34-45: Over-engineered simple logic
Actionable Fixes
-
Verbose Conditionals
// Replace if (obj && obj.prop && obj.prop.value) // With if (obj?.prop?.value)
-
Redundant Comments
- Remove comments that describe what code does
- Keep comments that explain why
-
Simplify Structure
- Use modern JavaScript features
- Remove unnecessary variables
- Combine operations
Integration Tips
Pre-commit Hook
#!/bin/bash
# .git/hooks/pre-commit
AI_SCORE=$(vibesweep analyze . --output json | jq '.summary.averageAIScore')
if [ $AI_SCORE -gt 50 ]; then
echo "Average AI score too high: $AI_SCORE"
echo "Please optimize AI-generated code before committing"
exit 1
fi
CI Pipeline
# .github/workflows/code-quality.yml
- name: Check AI Score
run: |
npx vibesweep analyze . --output json > report.json
MAX_SCORE=$(jq '.topOffenders[0].aiPatterns.score' report.json)
if [ $MAX_SCORE -gt 70 ]; then
echo "::error::High AI score detected: $MAX_SCORE"
exit 1
fi
Future Enhancements
- Machine learning model for better detection
- Language-specific patterns
- Framework-specific patterns (React, Vue, etc.)
- Historical trend analysis
- Team-specific pattern learning