Skip to content

AFS-Agentics/ai-diff

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Cover

πŸ€– ai-diff β€” AI-Powered Code Review CLI

Review your git diffs with AI. Find bugs, security vulnerabilities, and code quality issues before they hit production.

npm version License: MIT TypeScript CLI


✨ Features

  • πŸ” AI-Powered Analysis β€” Reviews your git diffs using any OpenAI-compatible LLM
  • πŸ› Bug Detection β€” Catches logical errors, edge cases, and runtime issues
  • πŸ”’ Security Scanning β€” Identifies hardcoded secrets, injection risks, PII leaks, and more
  • πŸ’‘ Actionable Suggestions β€” Gets refactoring ideas and best practice improvements
  • πŸ“Š Quality Score β€” Scores your code from 0–100 with clear breakdown
  • 🎨 Beautiful Output β€” Color-coded, human-readable terminal output with severity indicators
  • βš™οΈ Configurable β€” Multiple LLM providers, strictness levels, output formats
  • πŸ“‹ Commit Suggestions β€” Generates conventional commit messages from your changes

πŸš€ Installation

# Install via npm
npm install -g ai-diff

# Or run directly with npx
npx ai-diff

πŸ”‘ Setup

You need an API key from an OpenAI-compatible provider:

# Option 1: Environment variable
export AI_DIFF_API_KEY=sk-your-key-here
export AI_DIFF_MODEL=gpt-4o

# Option 2: Config file
ai-diff config --api-key sk-your-key-here --model gpt-4o

# Option 3: Use OPENAI_API_KEY (auto-detected)
export OPENAI_API_KEY=sk-your-key-here

Popular Providers

Provider Base URL Example Model
OpenAI https://api.openai.com/v1 gpt-4o, gpt-4o-mini
Anthropic https://api.anthropic.com/v1 claude-sonnet-4-6
Groq https://api.groq.com/openai/v1 llama-3.3-70b
Together https://api.together.xyz/v1 deepseek-ai/DeepSeek-V3
Ollama (local) http://localhost:11434/v1 deepseek-coder
# Example: Use Groq for fast reviews
ai-diff config --base-url https://api.groq.com/openai/v1 --model llama-3.3-70b

πŸ“– Usage

Review Staged Changes (Default)

# Stage your changes first
git add .

# Review them
ai-diff review
# or simply:
ai-diff

Review Specific Commit

ai-diff review --commit HEAD
ai-diff review --commit abc1234

Review Unstaged Changes

ai-diff review --unstaged

Output Formats

# Detailed (default) β€” full color-coded output
ai-diff review

# Concise β€” compact summary
ai-diff review --format concise

# JSON β€” machine-readable output
ai-diff review --format json | jq '.score'

Configuration Options

# View current config
ai-diff config --show

# Set API key
ai-diff config --api-key sk-...

# Set model
ai-diff config --model gpt-4o

# Set strictness level
ai-diff config --strictness aggressive

# Set temperature
ai-diff config --temperature 0.5

# Interactive setup wizard
ai-diff init

πŸ“‹ Example Output

╔══════════════════════════════════════════╗
β•‘       πŸ€– AI-DIFF β€” CODE REVIEW          β•‘
β•šβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•

Scope: staged changes
Files changed: 3
+42 -12

  ~ src/index.ts        +20 -5
  + src/ai.ts           +15 -0
  ~ src/config.ts       +7 -7

πŸ“Š Code Quality Score: 85/100

πŸ“ Summary:
Adds AI-powered code review functionality with OpenAI integration.

πŸ› Issues:

  ⚠ [HIGH] Unhandled promise rejection in async review
    File: src/ai.ts:42
    The API call may throw without a catch handler.

πŸ”’ SECURITY CONCERNS

  [HIGH] Hardcoded Secret β€” src/config.ts:15
    API key may be logged in error messages.
    β†’ Sanitize error messages before logging.

⚑ Advanced

Custom API Base URL

For self-hosted or alternative providers:

# Local Ollama
ai-diff config --base-url http://localhost:11434/v1 --model deepseek-coder

# Azure OpenAI
ai-diff config --base-url https://your-resource.openai.azure.com --model gpt-4o

CI/CD Integration

# GitHub Actions β€” fail on critical issues
ai-diff review --format json | jq -e '.issues | map(select(.severity == "critical")) | length == 0'

Pre-commit Hook

Add to your .git/hooks/pre-commit:

#!/bin/sh
npx ai-diff review --format concise

πŸ§ͺ How It Works

  1. Extracts the git diff from your repository (staged, unstaged, or commit)
  2. Sends the diff to an LLM with a structured review prompt
  3. Parses the AI response into a structured review (issues, security, suggestions)
  4. Displays the results with beautiful terminal formatting

Supports any OpenAI-compatible API β€” OpenAI, Anthropic, Groq, Together, Ollama, and more.


βš™οΈ Configuration Reference

Variable Config Key Default Description
AI_DIFF_API_KEY apiKey β€” API key for LLM provider
AI_DIFF_API_BASE_URL apiBaseUrl https://api.openai.com/v1 API base URL
AI_DIFF_MODEL model gpt-4o Model name
β€” strictness balanced conservative, balanced, or aggressive
β€” temperature 0.3 LLM temperature (0–2)
β€” maxDiffLines 2000 Max diff lines to send
β€” format detailed Output format

πŸ”§ Development

# Clone
git clone https://github.com/AFS-Agentics/ai-diff.git
cd ai-diff

# Install dependencies
npm install

# Build
npm run build

# Run locally
npm start -- review --help

πŸ—οΈ Built With

  • TypeScript β€” Type-safe, modern JavaScript
  • Commander β€” CLI framework
  • Chalk β€” Terminal styling
  • OpenAI SDK β€” LLM API client
  • Simple Git β€” Git operations

πŸ“„ License

MIT Β© AFS Agentics


🀝 Contributing

Contributions are welcome! Feel free to open issues or submit PRs.


Made with ❀️ by AFS Agentics

About

πŸ€– AI-Powered Code Review CLI β€” Analyze git diffs with LLMs to find bugs, security issues, and code quality problems

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors