Skip to main content

Automated AI-powered code review CLI for Azure DevOps / TFS Pull Requests

Project description

AI Code Review CLI

Automated code review tool with Pull Request integration for Azure DevOps/TFS and support for multiple LLM providers. Documentation where docs/index.md for complete guides on CLI usage, LLM configuration, and architecture.

Features

  • AI Pull Request Review — Automated code analysis with configurable LLM providers
  • Structured Comments — Inline suggestions + general summary comments
  • Dry-run Mode — Validate reviews before posting
  • Multiple LLM Providers — OpenAI, Azure OpenAI, Gemini, Claude, Ollama, GitHub Copilot, AWS Bedrock
  • Smart Filtering — Filter by file extensions, limit diff size
  • Project-aware PR Context — Sends repository and linked work item context while restricting findings to modified PR lines
  • Single Reviewer Context — One Markdown context file with local override support
  • Usage Tracking — Store per-PR token usage and optional cost estimates
  • Interactive CLI — Menu-driven selection and confirmation

Installation & Quick Start

1. Install Package

From PyPI:

pip install code-review-ai-cli

With optional LLM SDK extras:

pip install "code-review-ai-cli[bedrock]"    # AWS Bedrock
pip install "code-review-ai-cli[openai]"     # OpenAI SDK
pip install "code-review-ai-cli[gemini]"     # Google Gemini SDK
pip install "code-review-ai-cli[claude]"     # Anthropic Claude SDK
pip install "code-review-ai-cli[all]"        # All optional SDKs

For development:

pip install -r requirements.txt
pip install "code-review-ai-cli[dev]"        # Test suite + linting

2. Initialize Configuration

Generate config templates in your project directory:

ai-review init

Creates:

  • config.yaml — LLM and review settings
  • review_context.example.md — Canonical example reviewer context
  • review_context.local.md — Local reviewer context override, ignored by git
  • .gitignore entry for review_context.local.md

3. Run Your First Review

# List active PRs
ai-review list-prs

# Review a specific PR
ai-review pr-review 42

# Dry-run (preview without posting)
ai-review pr-review 42 --dry-run

# Check stored token/cost usage
ai-review usage

Configuration File

After ai-review init, edit config.yaml:

llm:
  provider: bedrock                    # or: openai, gemini, claude, etc.
  model: anthropic.claude-3-5-sonnet-20240620-v1:0

bedrock:
  region: us-east-1

tfs:
  base_url: https://dev.azure.com/your-org
  project: YourProject
  pat: xxxxxxxxx

review:
  language: pt
  verbosity: detailed                  # or: quick, security
  scope: diff_with_context             # diff_with_context, diff_only, full_code
  file_extensions_filter: [".cs", ".ts", ".py"]
  max_diff_files: 50
  max_comments_to_post: 20
  custom_prompt_file: review_context.local.md
  project_context:
    enabled: true
    mode: on_demand                      # on_demand, full
    manifest_max_chars: 60000
    retrieval_max_rounds: 2
    retrieval_max_files: 20
    retrieval_max_chars: 120000
    retrieval_file_max_chars: 30000
  work_item_context:
    enabled: true
    max_items: 20

By default, repository context is loaded on demand: the prompt includes explicit source-branch change packets, full changed-file contents as read-only context, linked work item documentation, and a repository manifest, then the model requests any extra files it needs. Inline PR comments must still be grounded in actual changed lines from the change packets. Set review.project_context.mode: full to send the full eligible repository snapshot instead. Bedrock uses a default estimated prompt budget of 180000 tokens; override it with llm.max_prompt_tokens if your model supports more or less.

Reviewer context is loaded from exactly one Markdown file. By default the CLI uses review_context.local.md when it exists, otherwise it falls back to the packaged src/prompts/review_context.example.md. Keep local team tweaks in review_context.local.md; it is gitignored so the canonical context cannot drift across machines.

For Copilot-backed reviews, Claude Sonnet models are often strong choices for large PR validation, for example llm.provider: copilot with a Claude Sonnet model available to your organization. The tool still enforces the same source-branch grounding, duplicate checks, and comment cap regardless of model.

Development & Testing

This is a standard Python project with the following structure:

src/
  ai_review.py        # CLI entry point
  config.py           # Configuration management
  llm_client.py       # LLM provider abstraction
  tfs_client.py       # Azure DevOps integration
  git_utils.py        # Git diff processing
  formatter.py        # Output formatting (terminal, markdown, JSON)

tests/
  test_*.py           # Unit and integration tests

Run Tests

python -m pytest --cov=src --cov-report=term

Code Quality

Project follows PEP8 with Black formatter and Ruff linter:

# Format code
black src/ tests/

# Lint
ruff check src/ tests/

# Type checking (if using mypy)
mypy src/

VS Code Integration

Predefined tasks for quick execution in VS Code:

Available Tasks

  1. AI Review: Pull Request (Interactive)
  • Interactive mode with main menu
  • Run with: Ctrl+Shift+B → Select task
  1. AI Review: PR (Dry-Run)
  • Dry-run for a specific PR
  • Prompts for PR ID
  1. AI Review: List Active PRs
  • Lists active PRs
  • Quick diagnostics
  1. AI Review: Interactive Mode
  • Full tool menu
  • Runs in background

How to run tasks

In VS Code:

  1. Ctrl+Shift+P → "Tasks: Run Task"
  2. Select the desired task
  3. Fill in parameters if needed

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

code_review_ai_cli-1.2.0.tar.gz (104.1 kB view details)

Uploaded Source

Built Distribution

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

code_review_ai_cli-1.2.0-py3-none-any.whl (77.9 kB view details)

Uploaded Python 3

File details

Details for the file code_review_ai_cli-1.2.0.tar.gz.

File metadata

  • Download URL: code_review_ai_cli-1.2.0.tar.gz
  • Upload date:
  • Size: 104.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for code_review_ai_cli-1.2.0.tar.gz
Algorithm Hash digest
SHA256 b3c8bebf5a3774568b94947f28bb4515444cb07caa3fc4ea9f6ef9315b5877f3
MD5 569578c3108a94da898849865ff306dc
BLAKE2b-256 c27e73e510594f69a70df1b7e170c92478fbde59a5920ee4f80209e1aca135f1

See more details on using hashes here.

File details

Details for the file code_review_ai_cli-1.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for code_review_ai_cli-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 494d3e2c2ee0bb37c48b675305c5df3245f586139f8de07f8b1f71b54f613461
MD5 9b5e041eb4c4b116fc74a4da276e529b
BLAKE2b-256 96afb769d91409d1d9584c6400a34a4e2838a2f77f3b6a54d443a56d0c40ed36

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