convez.ai
Agente
CrashBytes

ai-code-review-agent

CrashBytes/ai-code-review-agent

Ver no GitHub
InicialPluginScore · de 0 a 100

Production-ready AI code review automation using Claude API and GitHub Actions

Instalação

$npx convez-ai CrashBytes/ai-code-review-agent

1 comando no terminal: detecta o formato do repositório (marketplace ou plugin avulso) e instala via Claude Code. Requer Node 18+ e o Claude Code instalado.

Métricas

Estrelas
0
Forks
0
Acompanhando
0
Saúde
42%
Último commit
há 1 mês
Versão
—
Issues abertas
1
Contribuidores
3

README

A tradução para o português deste README ainda está na fila.

AI Code Review Agent

Production-ready AI code review automation using Claude API and GitHub Actions. Automatically analyzes pull requests for security vulnerabilities, code quality issues, and architectural concerns.

Features

  • Automated code review on every pull request
  • Security vulnerability detection (SQL injection, XSS, auth bypasses)
  • Code quality analysis (complexity, duplication, naming)
  • Architectural feedback (SOLID principles, coupling, scalability)
  • Performance issue identification (N+1 queries, inefficient algorithms)
  • Error handling validation (try-catch, promise rejections)
  • Configurable severity thresholds
  • Smart finding deduplication
  • Cost-effective token management
  • Production monitoring and metrics

Quick Start

1. Install in Your Repository

cd your-repo
npm install @anthropic-ai/sdk @octokit/rest

2. Add GitHub Actions Workflow

Create .github/workflows/ai-code-review.yml:

name: AI Code Review

on:
  pull_request:
    types: [opened, synchronize, reopened]

permissions:
  contents: read
  pull-requests: write
  
jobs:
  review:
    runs-on: ubuntu-latest
    timeout-minutes: 10
    
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0
          
      - uses: actions/setup-node@v4
        with:
          node-version: '18'
          cache: 'npm'
          
      - run: npm ci
        
      - name: Run AI code review
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: npx ai-code-review

3. Configure Secrets

  1. Get your Anthropic API key from https://console.anthropic.com
  2. Go to your repository Settings → Secrets and variables → Actions
  3. Add ANTHROPIC_API_KEY with your API key
  4. GITHUB_TOKEN is automatically provided

4. Customize Configuration (Optional)

Create .ai-review-config.json:

{
  "model": "claude-sonnet-4-20250514",
  "minSeverity": "medium",
  "reviewFocus": [
    "security-vulnerabilities",
    "code-quality",
    "architectural-concerns",
    "performance-issues",
    "error-handling"
  ],
  "excludePatterns": [
    "**/node_modules/**",
    "**/dist/**",
    "**/build/**"
  ]
}

Configuration Options

OptionTypeDefaultDescription
modelstringclaude-sonnet-4-20250514Claude model to use
maxTokensnumber4000Maximum tokens per response
temperaturenumber0.0Model temperature (0 = deterministic)
minSeveritystringmediumMinimum severity: low, medium, high, critical
reviewFocusarrayAll areasReview focus areas
excludePatternsarrayCommon artifactsFile patterns to exclude

Review Focus Areas

  • security-vulnerabilities: SQL injection, XSS, authentication bypasses
  • code-quality: Duplication, complexity, naming, magic numbers
  • architectural-concerns: SOLID violations, coupling, abstractions
  • performance-issues: N+1 queries, inefficient algorithms
  • error-handling: Missing try-catch, unhandled promises

Cost Management

Typical costs for a 100-developer team:

  • 50 pull requests/day
  • Average 10 files per PR
  • Approximately $75/month in API costs
  • $30/month in GitHub Actions usage
  • Total: ~$105/month

ROI: 190:1 return based on time savings

Example Output

The agent posts comments directly on pull requests:

### AI Code Review 🟠 HIGH

**Category**: security

**Issue**: SQL injection vulnerability due to string concatenation in database query

**Recommendation**: Use parameterized queries with prepared statements to prevent SQL injection attacks

**Example Fix**:
```javascript
// Instead of:
const query = `SELECT * FROM users WHERE id = ${userId}`;

// Use:
const query = 'SELECT * FROM users WHERE id = ?';
db.query(query, [userId]);

Finding ID: a1b2c3d4e5f6g7h8 Generated by AI Code Review Agent


## Advanced Usage

### Local Testing

```bash
export ANTHROPIC_API_KEY="your-key"
export GITHUB_TOKEN="your-token"
export GITHUB_EVENT_PATH="path/to/test-event.json"

node src/review-agent.js

Custom Severity Thresholds

{
  "minSeverity": "high"
}

Only critical and high severity findings will be posted.

Language-Specific Rules

{
  "fileTypeRules": {
    "typescript": {
      "requireTypes": true,
      "noExplicitAny": true
    },
    "python": {
      "checkTypeHints": true
    }
  }
}

Development

Running Tests

npm test

Linting

npm run lint

Architecture

GitHub PR → Webhook → GitHub Actions → Review Agent
                                          ↓
                              Claude API Analysis
                                          ↓
                              Finding Deduplication
                                          ↓
                              GitHub PR Comments

Security

  • API keys stored in GitHub Secrets
  • No code execution, only static analysis
  • Path traversal protection
  • File size limits
  • Input sanitization

Troubleshooting

No comments appear

  1. Check GitHub Actions logs for errors
  2. Verify ANTHROPIC_API_KEY is configured
  3. Ensure workflow has pull-requests: write permission
  4. Check file exclusion patterns aren't too broad

422 errors in logs

GitHub API returns 422 when comment line numbers don't exist in the diff. This is normal for files with extensive changes. The agent logs warnings but continues.

High costs

  1. Reduce maxTokens in configuration
  2. Add more exclusion patterns
  3. Increase minSeverity threshold
  4. Review file chunking strategy

Contributing

Contributions welcome! See CONTRIBUTING.md

License

MIT License - see LICENSE

Support

Related Projects


Built with Claude API by CrashBytes

Ver o original no GitHub

Bom para

Relacionados