Skip to content

deepmtch/codewatch-ai

Repository files navigation

CodeWatch

AI-powered code analysis that watches your changes

CodeWatch uses AI (Cerebras) to check your code changes against customizable rules. Violations are automatically copied to clipboard so you can paste to AI for instant fixes.

Features

  • 🔍 Check uncommitted changes, commits, or commit ranges
  • 🤖 AI-powered analysis using Cerebras
  • 📋 Simple rule groups (security, performance, ui, style)
  • 📋 Auto-copy to clipboard - paste to AI for fixes
  • 🎨 Beautiful terminal output
  • 📊 Multiple formats: console, JSON, markdown
  • 🚀 CI/CD ready

Quick Start

Install

pip install -e .

Setup

# 1. Initialize
codewatch init

# 2. Set API key
export CEREBRAS_API_KEY="your-key"

# 3. Create rules
cp default-rules.json rules.json

Basic Usage

# Check uncommitted changes
codewatch

# Check specific commit
codewatch -c abc123

# Check commit range
codewatch -r main..feature

# Filter by group
codewatch -g security

# JSON output
codewatch -f json -o report.json

# Don't copy to clipboard
codewatch --no-copy

Rules

Rules are simple:

{
  "id": 1,
  "name": "No hardcoded secrets",
  "prompt": "Check for hardcoded API keys",
  "group": "security"
}

Groups: security, performance, ui, style, etc.

Create Rules

# Interactive
codewatch setup

# With AI
codewatch add-rule "Check for SQL injection"

# Generate multiple
# (in setup menu, option 4)

Generate Sample Code

# Generate new examples
codewatch generate "Python API code"

# Modify existing file
codewatch generate "add hardcoded password" myfile.py

Pre-commit Hook

codewatch install-hook

What happens:

  1. Try to commit
  2. CodeWatch runs
  3. Violations found → auto-copied to clipboard
  4. Paste to Claude/AI to get fixes
  5. Apply fixes and commit

Configuration

Location: ~/.codewatch/config.json

{
  "cerebras": {
    "api_key": "your-key",
    "model": "llama3.1-8b",
    "endpoint": "https://api.cerebras.ai/v1"
  },
  "rules": {
    "path": "./rules.json"
  }
}

Update:

codewatch config --set cerebras.api_key=sk-xxx

Output

example.py:10 (2 violations)
  password = "admin123"
  ☐ Rule 1: Hardcoded password
  ☐ Rule 16: Sensitive credential

✓ Copied to clipboard

Paste violations to AI → get fixes → apply → done!

Commands

codewatch              # Check changes
codewatch setup        # Interactive setup
codewatch add-rule     # Add rule with AI
codewatch generate     # Generate code
codewatch install-hook # Install pre-commit hook
codewatch config       # View/edit config

Short Flags

  • -c commit
  • -r range
  • -b branch
  • -f format
  • -o output
  • -v verbose
  • -g group
  • -h help

Exit Codes

  • 0 = Pass
  • 1 = Fail (violations)
  • 2 = Error

CI/CD

- name: CodeWatch
  run: codewatch -r ${{ github.base }}..${{ github.head }}
  env:
    CEREBRAS_API_KEY: ${{ secrets.CEREBRAS_API_KEY }}

Troubleshooting

"API key not configured"

export CEREBRAS_API_KEY="your-key"

"Rules file not found"

cp default-rules.json rules.json

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors