Skip to main content

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

Python 3.7+ License: MIT Code style: black

๐Ÿš€ 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

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
  1. Analyzes Your Repository - Finds similar files to understand patterns
  2. Reads Config Files - Checks .editorconfig, .eslintrc, pyproject.toml, etc.
  3. Reviews Only Changes - Focuses on new/modified lines in staged files
  4. 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
  1. Update version in __init__.py, setup.py, and pyproject.toml
  2. Run tests: python -m pytest tests/
  3. Build package: python -m build
  4. Test on TestPyPI: python -m twine upload --repository testpypi dist/*
  5. Release: python -m twine upload dist/*
  6. Tag release: git tag -a v1.1.0 -m "Release v1.1.0"

๐Ÿค Contributing

We welcome contributions! Here's how to help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes and add tests
  4. Ensure tests pass (python -m pytest)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. 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

marsdevs-reviewer-1.1.2.tar.gz (30.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

marsdevs_reviewer-1.1.2-py3-none-any.whl (101.5 kB view details)

Uploaded Python 3

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

Hashes for marsdevs-reviewer-1.1.2.tar.gz
Algorithm Hash digest
SHA256 ce65c2e6d5254970dd0595d4b751f8138204d94d0462086704b1fcd8f4eda021
MD5 e565b1d5ff05ba61ac1fcdf6da51c3dd
BLAKE2b-256 14e2572f04caee14a145339b003688dd08a709248c729470b8f458211980ea6b

See more details on using hashes here.

File details

Details for the file marsdevs_reviewer-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for marsdevs_reviewer-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 68ae132ffec224a173fbca8bcdecbd5ed3dd54b7145b3852c779e9be3da18049
MD5 15c8a6b74d99c83dd2347ea1a28d397a
BLAKE2b-256 975767a14122d2d8f09337e8c246d2f6bf965eea2127cfe182ab31ee8f48a601

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page