JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q84114F
  • License MIT

AI-powered pre-commit code review tool

Package Exports

  • ai-commit-guard
  • ai-commit-guard/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ai-commit-guard) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

AI Commit Guard

๐Ÿค– AI-powered pre-commit code review tool that automatically checks your code changes before commit using OpenAI GPT-4 or Anthropic Claude.

npm version License: MIT Node.js Version

โœจ Features

  • ๐Ÿ” Smart Detection - Only reviews staged .js, .ts, .jsx, .tsx, .vue, .py files
  • ๐Ÿš€ Lightning Fast - Cached results for unchanged code
  • ๐ŸŽฏ Custom Rules - Define your own coding standards
  • ๐Ÿ”„ Multi-Provider - Works with OpenAI GPT-4 or Anthropic Claude
  • ๐Ÿ›ก๏ธ Zero Config - Works out of the box with sensible defaults
  • ๐Ÿ“ Detailed Feedback - Get specific line-by-line suggestions

๐Ÿš€ Quick Start

1. Install Globally

npm install -g ai-commit-guard

2. Setup in Your Project

# Install husky (if not already installed)
npm install --save-dev husky
npx husky init

# Add AI Guard to pre-commit hook
echo "npx ai-commit-guard" > .husky/pre-commit
chmod +x .husky/pre-commit

3. Set Your AI API Key

Option A: OpenAI (Recommended)

export OPENAI_API_KEY="sk-your-openai-key-here"

Option B: Anthropic Claude

export CLAUDE_API_KEY="sk-ant-your-claude-key-here"
export AI_PROVIDER="claude"

4. That's It! ๐ŸŽ‰

Now AI Guard will automatically review your code on every commit:

git add .
git commit -m "feat: add user authentication"
# โ†’ AI Guard automatically reviews your changes

๐Ÿ“‹ Custom Rules (Optional)

Create a .code-rules.md file in your project root to define custom coding standards:

# My Code Review Rules

## Magic Strings
- No string literals in code, use constants
- Event properties should use EVENT_FIELDS constant

## Functions
- Functions should not exceed 20 lines
- Use descriptive function names
- Follow single responsibility principle

## Variables
- Use camelCase for variables
- Boolean variables should start with is/has/can/should
- No single letter variables except for loops

## Error Handling
- Always use try-catch for async operations
- Log errors with appropriate context

## Examples

โŒ **Bad:**
```javascript
event['status'] = 'active';
function getData() { /* 30 lines of mixed responsibilities */ }
let x = true;

โœ… Good:

const EVENT_FIELDS = { STATUS: 'status' };
event[EVENT_FIELDS.STATUS] = 'active';

function fetchUserData() { /* single responsibility */ }
function processUserData() { /* separate concern */ }

let isUserActive = true;

## ๐Ÿ› ๏ธ Usage

### Automatic Mode (Recommended)
AI Guard runs automatically when you commit:

```bash
git add src/
git commit -m "refactor: improve error handling"
# ๐Ÿ” Checking staged files...
# ๐Ÿ“ Reviewing 3 files...
# ๐Ÿค– Sending to AI for review...
# โœ… Code review passed!

Manual Mode

Run review without committing:

npx ai-commit-guard

Test Mode

Check if everything is working:

# Test with sample code
npx ai-commit-guard --test

๐Ÿ“Š Example Output

โœ… Passing Review

๐Ÿ” Checking staged files...
๐Ÿ“ Reviewing 2 files...
๐Ÿค– Sending to AI for review...
โœ… Code review passed!

๐Ÿ’ก Suggestions:
โ€ข Consider adding JSDoc comments for public functions
โ€ข Variable naming looks great, well done!

โŒ Failing Review

๐Ÿ” Checking staged files...
๐Ÿ“ Reviewing 3 files...
๐Ÿค– Sending to AI for review...
โŒ Code review failed!

Issues found:
โ€ข src/utils.js: Magic string 'status' on line 15
  Fix: Use EVENT_FIELDS.STATUS constant

โ€ข src/api.js: Function getUserData() is 25 lines long
  Fix: Split into fetchUser() and processUser() functions

โ€ข src/components/User.tsx: Variable 'x' is not descriptive
  Fix: Rename to 'isUserLoggedIn' or similar

โš™๏ธ Configuration

Environment Variables

Variable Description Default
OPENAI_API_KEY Your OpenAI API key -
CLAUDE_API_KEY Your Claude API key -
AI_PROVIDER AI provider: openai or claude openai

Files

File Purpose
.code-rules.md Your custom coding rules
.ai-guard-cache/ Cache directory (auto-created)

๐ŸŽฏ Supported File Types

  • JavaScript: .js
  • TypeScript: .ts
  • React: .jsx, .tsx
  • Vue: .vue
  • Python: .py

๐Ÿ”ง Advanced Usage

Different Rules Per Project

# Create project-specific rules
echo "# Strict React Rules\n- All components must have PropTypes" > .code-rules.md

Temporary Disable

# Skip AI review for this commit
git commit -m "docs: update README" --no-verify

Clear Cache

# Remove cached reviews
rm -rf .ai-guard-cache

๐Ÿค” Why AI Commit Guard?

Problem Solution
๐Ÿ˜ฐ Inconsistent code style across team โœ… Enforces rules automatically
๐Ÿ˜ด Bugs slip through manual review โœ… AI catches common mistakes
๐Ÿ˜ฌ Junior developers need guidance โœ… Educational feedback on every commit
๐Ÿ˜ค Code review takes too long โœ… Pre-filter obvious issues
๐Ÿ˜ต Forget to follow team standards โœ… Instant feedback at commit time

๐Ÿ†š Comparison

Feature AI Commit Guard ESLint Manual Review
Custom Rules โœ… Natural language โš ๏ธ Config syntax โœ… Human judgment
Context Aware โœ… Understands logic โŒ Syntax only โœ… Full context
Learning โœ… Teaches best practices โŒ Just flags errors โš ๏ธ Inconsistent
Speed โœ… Instant (cached) โœ… Very fast โŒ Slow
Flexibility โœ… Any rule you write โš ๏ธ Predefined rules โœ… Completely flexible

๐Ÿ› Troubleshooting

Common Issues

"No AI API key found"

# Check if key is set
echo $OPENAI_API_KEY

# Set the key
export OPENAI_API_KEY="sk-your-key-here"

# Make it permanent (add to ~/.bashrc or ~/.zshrc)
echo 'export OPENAI_API_KEY="sk-your-key-here"' >> ~/.bashrc

"Not a git repository"

# Initialize git first
git init
git add .
git commit -m "initial commit"

"No staged files to review"

# Make sure files are staged
git status
git add .

"AI connection failed"

# Check your API key and internet connection
curl -H "Authorization: Bearer $OPENAI_API_KEY" https://api.openai.com/v1/models

Performance Tips

  • ๐Ÿƒโ€โ™‚๏ธ Enable caching: Cache is enabled by default
  • ๐Ÿ“ Stage only what you need: git add specific-file.js
  • ๐ŸŽฏ Use specific rules: More specific rules = faster reviews
  • ๐Ÿงน Clean cache periodically: rm -rf .ai-guard-cache

๐Ÿ“ˆ Roadmap

  • Support for more file types (Go, Rust, C++)
  • Integration with popular IDEs
  • Team dashboards and analytics
  • Custom AI model fine-tuning
  • Slack/Discord notifications
  • CI/CD pipeline integration

๐Ÿค Contributing

We love contributions! Here's how to help:

  1. ๐Ÿด Fork the repository
  2. ๐ŸŒฑ Create your feature branch: git checkout -b my-feature
  3. โœ… Commit your changes: git commit -m 'Add cool feature'
  4. ๐Ÿš€ Push to the branch: git push origin my-feature
  5. ๐Ÿ“ Open a Pull Request

๐Ÿ“„ License

MIT ยฉ Adem Alkan

Made with โค๏ธ for better code quality

Star โญ this repo if it helps you write better code!