AI-powered code review tool that learns from your repository
Project description
MarsDevs Code Reviewer
๐ AI-powered pre-commit hook that learns your codebase conventions and ensures consistent, high-quality code
๐ What is MarsDevs Code Reviewer?
MarsDevs Code Reviewer is an intelligent Git pre-commit hook that automatically reviews your staged changes against your repository's existing coding patterns. Unlike generic linters, it learns from your codebase to enforce your team's specific conventions.
Key Benefits
โ
Zero Configuration - Automatically learns from your existing code
โ
Repository-Specific - Enforces YOUR conventions, not generic rules
โ
Interactive Fixes - Accept or reject suggested changes
โ
Fast Reviews - Smart caching for instant re-reviews
โ
Non-Intrusive - Only reviews new changes, not existing code
โ
Machine Learning - Learns from your decisions to reduce API calls over time
๐ฆ Installation
Prerequisites
- Python 3.7 or higher
- Git repository
- Anthropic API key
Install from PyPI
pip install marsdevs-reviewer
Set up your API key
# Add to your shell profile (~/.bashrc, ~/.zshrc, etc.)
export ANTHROPIC_API_KEY='sk-ant-...'
Enable in your repository
cd your-project
marsdevs-reviewer install
That's it! ๐ MarsDevs will now review all your commits automatically.
๐ฏ How It Works
Click to see how MarsDevs learns your conventions
- Analyzes Your Repository - Finds similar files to understand patterns
- Reads Config Files - Checks
.editorconfig,.eslintrc,pyproject.toml, etc. - Reviews Only Changes - Focuses on new/modified lines in staged files
- Suggests Fixes - Provides corrections that match your codebase style
Example Review Session
$ git commit -m "Add user authentication"
Running MarsDevs Code Reviewer...
๐ Analyzing repository coding conventions...
๐ Reviewing staged changes against repository conventions...
Found 2 convention issue(s) to review...
------------------------------------------------------------
ISSUE: CONVENTION
File: src/auth.py
Lines: 23-23
Convention Violated: Use project's logging pattern
Example from Codebase:
logger.info(f"User {user_id} logged in")
Description: Using print() instead of logger
Explanation: Other auth modules use logger.info for consistency
--- Current Code ---
print(f"User {user_id} authenticated")
--- Suggested Fix ---
logger.info(f"User {user_id} authenticated")
------------------------------------------------------------
Apply this fix? (y)es / (n)o / (s)kip all / (q)uit: y
โ
Fix applied successfully!
๐ ๏ธ Commands
| Command | Description |
|---|---|
marsdevs-reviewer install |
Install pre-commit hook in current repo |
marsdevs-reviewer uninstall |
Remove pre-commit hook |
marsdevs-reviewer review |
Manually review staged changes |
marsdevs-reviewer stats |
Show learning statistics |
marsdevs-reviewer clear-cache |
Clear the review cache |
marsdevs-reviewer export-learning |
Export learned conventions |
marsdevs-reviewer reset-learning |
Reset learning data |
marsdevs-reviewer --help |
Show help message |
๐ง Learning System
MarsDevs learns from your decisions to improve over time:
- Accepted fixes increase pattern confidence
- Rejected fixes decrease pattern confidence
- High confidence patterns (>70%) skip API calls
- Learning data stored locally in
.marsdevs/directory
Check your learning progress:
marsdevs-reviewer stats
โ๏ธ Configuration
Skipped Files
By default, these file types are skipped:
- Documentation:
.md,.txt - Config files:
.json,.yml,.yaml,.toml - Lock files:
package-lock.json,*.lock - Media:
.jpg,.png,.gif,.svg
Bypass Review
Need to skip the review temporarily?
git commit --no-verify -m "Emergency hotfix"
Debug Mode
Having issues? Enable debug mode:
export MARSDEVS_DEBUG=1
export MARSDEVS_LOG_LEVEL=DEBUG
git commit -m "Debug commit"
๐ Troubleshooting
MarsDevs is not running on commit
# Check if hook is installed
ls -la .git/hooks/pre-commit
# Make hook executable
chmod +x .git/hooks/pre-commit
# Check Git hooks path
git config core.hooksPath
Import or command not found errors
# Verify installation
pip show marsdevs-reviewer
# Reinstall
pip install --upgrade marsdevs-reviewer
# Check Python path
which python3
which marsdevs-reviewer
API connection issues
# Verify API key is set
echo $ANTHROPIC_API_KEY
# Test API connection
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01"
๐จโ๐ป Development
Setting up for development
# Clone and setup
git clone http://github.com/marsdevs-com/marsdevs-reviewer/
cd marsdevs-reviewer
python3 -m venv venv
source venv/bin/activate
pip install -e .
# Run tests
python -m pytest tests/ -v
# Enable debug logging
export MARSDEVS_DEBUG=1
Project structure
marsdevs_reviewer/
โโโ __init__.py # Package metadata
โโโ reviewer.py # Core review logic
โโโ cli.py # Command-line interface
โโโ debug.py # Debug utilities
โโโ learning/ # Machine learning system
โโโ __init__.py
โโโ learning_manager.py # Manages persistent storage
โโโ convention_extractor.py # Extracts patterns
โโโ pattern_matcher.py # Matches against learned patterns
โโโ models.py # Data structures
Adding new features
# Add new review check in reviewer.py
def review_code_with_conventions(diff, files, conventions_context):
prompt = f"""...existing prompt...
6. **Security Issues**: Check for exposed secrets or API keys
"""
# Add new CLI command in cli.py
def stats_command():
"""Show review statistics."""
# Implementation
# Register in main()
parser.add_argument('command',
choices=['install', 'uninstall', 'review', 'clear-cache', 'stats'])
๐ Publishing to PyPI
Release checklist
- Update version in
__init__.py,setup.py, andpyproject.toml - Run tests:
python -m pytest tests/ - Build package:
python -m build - Test on TestPyPI:
python -m twine upload --repository testpypi dist/* - Release:
python -m twine upload dist/* - Tag release:
git tag -a v1.1.0 -m "Release v1.1.0"
๐ค Contributing
We welcome contributions! Here's how to help:
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Make your changes and add tests
- Ensure tests pass (
python -m pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- Built with Anthropic's Claude API
- Inspired by the need for repository-specific code standards
- Thanks to all contributors and early testers
๐ Star this repo if you find it helpful!
Report Bug โข
Request Feature โข
Discussions
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file marsdevs-reviewer-1.1.2.tar.gz.
File metadata
- Download URL: marsdevs-reviewer-1.1.2.tar.gz
- Upload date:
- Size: 30.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce65c2e6d5254970dd0595d4b751f8138204d94d0462086704b1fcd8f4eda021
|
|
| MD5 |
e565b1d5ff05ba61ac1fcdf6da51c3dd
|
|
| BLAKE2b-256 |
14e2572f04caee14a145339b003688dd08a709248c729470b8f458211980ea6b
|
File details
Details for the file marsdevs_reviewer-1.1.2-py3-none-any.whl.
File metadata
- Download URL: marsdevs_reviewer-1.1.2-py3-none-any.whl
- Upload date:
- Size: 101.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
68ae132ffec224a173fbca8bcdecbd5ed3dd54b7145b3852c779e9be3da18049
|
|
| MD5 |
15c8a6b74d99c83dd2347ea1a28d397a
|
|
| BLAKE2b-256 |
975767a14122d2d8f09337e8c246d2f6bf965eea2127cfe182ab31ee8f48a601
|