An intelligent AI-powered assistant that automatically scans codebases for bugs, generates fixes using Claude or GPT, validates changes with automated tests, and integrates fixes into your codebase via pull requests.
Bug-Fixing-AI-Assistant/
βββ scanner/ # Code scanning and bug detection
β βββ core/ # Core scanning functionality
β β βββ scanner.py # Base scanner class
β β βββ report.py # Report generation
β βββ detectors/ # Bug detection modules
β βββ pattern_detector.py # Pattern-based bug detection
β βββ security_detector.py # Security vulnerability detection
βββ fixer/ # Bug fixing and code generation
β βββ generators/ # Fix generation modules
β β βββ fix_generator.py # Base fix generator
β β βββ patch_generator.py # Patch and diff generation
β βββ validators/ # Fix validation modules
β βββ fix_validator.py # Fix syntax validation
β βββ test_runner.py # Test execution
βββ pr-handler/ # Pull request management
β βββ pr_creator.py # PR creation and management
βββ examples/ # Example buggy and fixed code
β βββ buggy_code.py # Intentionally buggy code samples
β βββ fixed_code.py # Fixed versions of buggy code
β βββ README.md # Example documentation
βββ tests/ # Comprehensive test suite
βββ test_scanner.py # Scanner tests
βββ test_detectors.py # Detector tests
βββ test_fixer.py # Fixer tests
βββ test_pr_handler.py # PR handler tests
βββ README.md # Test documentation
- Pattern Detection: Identifies common code anti-patterns
- None comparison using
==instead ofis - Bare except clauses
- Mutable default arguments
- Wildcard imports
- None comparison using
- Security Analysis: Detects security vulnerabilities
- Dangerous
eval()andexec()usage - Unsafe deserialization (pickle)
- Insecure module imports
- Dangerous
- Code Quality: Analyzes code quality issues
- High cyclomatic complexity
- Too many function arguments
- Missing docstrings
- Magic numbers
- Functions with too many methods (God objects)
- Claude Integration: Uses Anthropic's Claude for intelligent fixes
- OpenAI Integration: Supports GPT-4 and GPT-3.5-turbo
- Context-Aware: Provides surrounding code context to AI
- Confidence Scoring: AI rates fix confidence level
- Fallback Support: Falls back to rule-based fixes when AI unavailable
- Smart Application: Automatically applies fixes to files
- Backup Creation: Creates backups before modifying files
- Syntax Validation: Validates fixed code syntax before applying
- Dry Run Mode: Preview changes without modifying files
- Batch Processing: Apply multiple fixes at once
- Python Syntax Validation: Ensures fixes don't introduce syntax errors
- Test Execution: Runs pytest or unittest after fixing
- Configurable: Control whether tests must pass
- Fix Verification: Validates fixes before committing
- Automated Branching: Creates feature branches automatically
- Smart Commits: Generates descriptive commit messages
- PR Descriptions: Creates detailed PR descriptions with fix summaries
- Auto-Push: Optionally pushes to remote automatically
- GitHub Integration: Works with gh CLI for PR creation
- Clone the repository:
git clone https://github.com/matthewnyc2/Bug-Fixing-AI-Assistant.git
cd Bug-Fixing-AI-Assistant- Install dependencies (optional, for AI features):
# For Anthropic Claude
pip install anthropic
# For OpenAI GPT
pip install openai
# Or install all optional dependencies
pip install -e ".[full]"- Set up your AI API key (optional):
# For Anthropic Claude
export ANTHROPIC_API_KEY=your-api-key-here
# For OpenAI GPT
export OPENAI_API_KEY=your-api-key-here# Scan current directory and show report
python main.py
# Scan a specific directory
python main.py /path/to/your/project
# Generate JSON report
python main.py --report json# Scan and generate AI fixes (dry run - no changes)
python main.py --ai --dry-run
# Scan, generate AI fixes, and apply them
python main.py --ai --apply
# Full workflow: scan, fix, test, and create PR
python main.py --ai --apply --run-tests --create-pr# Copy example config
cp config.example.yaml config.yaml
# Edit config.yaml with your preferences
# Then run with config
python main.py --config config.yaml --ai --applyfrom main import BugFixingAssistant
# Create assistant
assistant = BugFixingAssistant()
# Scan directory
issues = assistant.scan_directory('.')
# Print issues
for issue in issues:
print(f"{issue['type']} at {issue['file']}:{issue['line']}")from main import BugFixingAssistant
from config import Config
# Create config with AI enabled
config = Config()
config.set('ai.provider', 'anthropic')
config.set('ai.model', 'claude-sonnet-4-5-20250929')
# Create assistant
assistant = BugFixingAssistant(config)
# Scan and fix
issues = assistant.scan_directory('.')
fixes = assistant.generate_fixes(use_ai=True)
# Apply fixes (with backup)
results = assistant.apply_fixes()
# Show what was fixed
for result in results:
if result['success']:
print(f"β Fixed {result['file']}")
print(result['diff'])from main import BugFixingAssistant
assistant = BugFixingAssistant()
issues = assistant.scan_directory('.')
fixes = assistant.generate_fixes()
assistant.apply_fixes()
# Create PR with fixes
pr_result = assistant.create_pr(fixes)
print(pr_result['pr_description'])Run all tests:
python -m unittest discover tests -vRun specific test suite:
python -m unittest tests.test_scanner -v
python -m unittest tests.test_detectors -v
python -m unittest tests.test_fixer -v
python -m unittest tests.test_pr_handler -vThe examples/ directory contains sample files demonstrating the assistant's capabilities:
- buggy_code.py: Contains intentional bugs for testing
- fixed_code.py: Shows corrected versions of the bugs
- README.md: Detailed explanation of each bug and fix
Test the scanner on examples:
python -c "
from scanner.detectors.pattern_detector import detect_patterns
from scanner.detectors.security_detector import detect_security_issues
from pathlib import Path
file_path = Path('examples/buggy_code.py')
with open(file_path) as f:
content = f.read()
issues = detect_patterns(file_path, content) + detect_security_issues(file_path, content)
print(f'Found {len(issues)} issues')
"- Python 3.7+
- No external dependencies for core functionality
- Uses Python standard library only
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests to ensure everything works
- Submit a pull request
The scanner module is responsible for analyzing code and detecting potential issues. It uses Python's ast module for syntax tree analysis.
The fixer module generates suggested fixes for detected issues. It includes validators to ensure fixes don't introduce new problems.
The PR handler automates the process of creating pull requests with fixes, including branch management and commit operations.
| Issue Type | Severity | Auto-Fix | AI-Fix |
|---|---|---|---|
| Pattern Issues | |||
None comparison (== instead of is) |
Warning | β Yes | β Yes |
| Bare except clause | Warning | β Yes | β Yes |
| Mutable default argument | Warning | β No | β Yes |
| Wildcard import | Info | β No | β Yes |
| Security Issues | |||
Dangerous eval() usage |
Critical | β No | β Yes |
Dangerous exec() usage |
Critical | β No | β Yes |
| Unsafe pickle deserialization | High | β No | β Yes |
| Insecure module import | Info | β No | β Yes |
| Quality Issues | |||
| High cyclomatic complexity | Warning | β No | β Yes |
| Too many function arguments | Info | β No | β Yes |
| Missing docstrings | Info | β No | β Yes |
| Magic numbers | Info | β No | β Yes |
| Too many methods (God object) | Warning | β No | β Yes |
| Assert in production code | Info | β No | β Yes |
Legend:
- β Yes = Fully automated fix available
- β No = Requires manual intervention or AI
- AI-Fix = Can be fixed using AI (Claude/GPT)
- Automated fix application
- AI-powered bug detection and fixing
- Code quality metrics and complexity analysis
- Comprehensive test suite
- Configuration file support
- Pull request automation
- Support for more programming languages (JavaScript, TypeScript, Java, Go)
- Integration with CI/CD pipelines (GitHub Actions, GitLab CI)
- Web dashboard for visualization
- Custom rule definitions and plugins
- Performance optimization analysis
- Dead code detection
- Dependency vulnerability scanning
- Integration with issue trackers (Jira, Linear)
- Multi-file refactoring support
- Incremental scanning (only changed files)
This project is open source. See LICENSE file for details.
For questions or suggestions, please open an issue on GitHub.