Skip to main content

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

Project description

AI Code Review

Automated code review tool with Pull Request integration for Azure DevOps/TFS and support for multiple LLM providers.

The main entry point is in src/ai_review.py. The project also includes dedicated modules for configuration, output formatting, Git diff capture, TFS/Azure DevOps integration, and communication with the LLM provider.

Features

  • AI Pull Request review (pr-review)
  • Structured PR comments (inline + general summary)
  • dry-run mode to validate without posting
  • PR listing with filters (list-prs)
  • Configuration exclusively via config.yaml
  • Providers LLM: OpenAI, Azure OpenAI, Gemini, Claude, Ollama, GitHub Copilot, AWS Bedrock

Installation

Install from PyPI:

pip install code-review-ai-cli

Or install 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

All providers also work without their optional SDK — the tool communicates via HTTP directly.

If you plan to run the test suite locally, also install development dependencies:

pip install "code-review-ai-cli[dev]"

Configuration

After installing the package, generate ready-to-edit configuration files in your working directory:

ai-review init

This copies two bundled templates:

  • config.yaml — all available options with inline documentation
  • review_prompt.md — default review style rules, injected into every LLM prompt
✅ config.yaml created at: /home/user/my-project/config.yaml
✅ review_prompt.md created at: /home/user/my-project/review_prompt.md
   Edit them to add your credentials, preferences and review rules.

If either file already exists you will be prompted individually before it is overwritten:

config.yaml already exists in the current directory.
Overwrite? [y/N]

The tool looks for config.yaml in the current working directory at runtime. You can also pass a different path with --config:

ai-review pr-review --config ~/configs/ai-review.yaml

Minimal Example

llm:
  provider: openai
  model: gpt-4o

openai:
  api_key: sk-xxxx

tfs:
  base_url: https://dev.azure.com/your-organization
  project: ProjectName
  pat: xxxxxxxxx
  verify_ssl: true
  # ca_bundle: C:/certs/corporate-root-ca.pem

review:
  language: pt
  verbosity: detailed
  scope: diff_only
  custom_prompt_file: review_prompt.md
  # file limit sent to the LLM
  max_diff_files: 50
  # per-file limit
  max_diff_lines: 2000
  # extension allowlist (empty list = all files)
  file_extensions_filter: [".cs", ".ts", ".py"]

pr:
  auto_post_comments: false
  dry_run: false
  comment_mode: structured

output:
  format: terminal
  file: ""
  color: true

Review Scope

review.scope controls how much code is sent to the LLM for each changed file.

Scope Description
diff_only Default. Unified diff (changed lines only) + full file content as read-only context.
full_code All lines of the new file version, every line prefixed with +. No baseline.

diff_only — diff with full-file context (default)

review:
  scope: diff_only
  scope: full_code

When diff_only is active, the tool:

  1. Generates a standard unified diff (added/removed lines with 3 lines of surrounding context) for each changed file.
  2. Appends the complete new-version file content as a clearly-marked, read-only context block immediately after the diff for that file:
  3. Strips all context lines and deleted lines (-) before sending to the LLM, so only added lines (+) and structural headers remain in the diff section.
  4. Instructs the LLM (via the system prompt) to use the full-file block as read-only background and to focus the review exclusively on the + lines.

full_code — entire new file as added lines

Every line of the new file version is prefixed with + and sent without a - baseline. The LLM receives the complete content and is asked to review only the new code. This is more expensive and slower but may catch issues in unchanged lines that are affected by the changes.

Filter by File Extension

file_extensions_filter works as an allowlist: only files with listed extensions are sent to the LLM for review. Remaining files are excluded from the diff before any processing.

review:
  # Review only C#, TypeScript, and Python code
  file_extensions_filter: [".cs", ".ts", ".py"]

To review all PR files, leave the list empty:

review:
  file_extensions_filter: []

Note: If no eligible files remain after filtering, the review ends with a warning without calling the LLM.

Markdown-Customizable Prompt

ai-review init creates a review_prompt.md alongside config.yaml. This file is loaded automatically and injected into LLM instructions on every run.

Edit it to tailor the review to your team:

  • Define comment tone and format
  • Add mandatory validation rules
  • Include business/architecture context
  • Add examples of good/bad comments

The path is configurable in config.yaml (default: review_prompt.md in the current directory):

review:
  custom_prompt_file: review_prompt.md

Bedrock Example

Option 1 — Bedrock long-term API key (AWS Console → Amazon Bedrock → API Keys):

llm:
  provider: bedrock
  model: arn:aws:bedrock:eu-north-1:123456789:application-inference-profile/xxxxxxxx

bedrock:
  region: eu-north-1
  access_key_id: ABSK...   # long-term API key — no secret_access_key

Option 2 — IAM explicit credentials (access key ID + secret):

llm:
  provider: bedrock
  model: anthropic.claude-3-5-sonnet-20240620-v1:0

bedrock:
  region: us-east-1
  access_key_id: AKIA...
  secret_access_key: wJalr...
  # session_token: ...   # optional, for temporary STS credentials

Option 3 — AWS SSO / named profile:

bedrock:
  region: us-east-1
  profile: my-sso-profile

CLI Usage

Help

ai-review pr-review --help

Bootstrap configuration

Generate config.yaml and review_prompt.md templates in the current directory:

ai-review init

Interactive Mode

 ai-review pr-review

Pull Request Review

List PRs and select interactively:

 ai-review pr-review pr-review

Review a specific PR:

 ai-review pr-review pr-review 42

Dry-run:

 ai-review pr-review pr-review 42 --dry-run

Full review of changed files (in addition to diff-focused review):

 ai-review pr-review pr-review 42 --review-scope full_code

Automatic posting (without confirmation):

 ai-review pr-review pr-review 42 --auto-post

Filter PRs in interactive selection:

 ai-review pr-review pr-review --author "John Smith" --target-branch main

Choose provider/model via CLI:

 ai-review pr-review pr-review 42 --provider bedrock --model anthropic.claude-3-5-sonnet-20240620-v1:0

List Pull Requests

 ai-review pr-review list-prs
 ai-review pr-review list-prs --status completed
 ai-review pr-review list-prs --repo-name backend --author "John"

Execution Flow

The diagram below summarizes how the review application moves from CLI entry to PR analysis and comment posting.

flowchart TD
  A[Start:  ai-review pr-review] --> B{Arguments provided?}
  B -->|No| C[Interactive mode]
  B -->|Yes| D[Parse CLI command]

  C --> E{Choose action}
  E -->|PR review| F[Start PR review workflow]
  E -->|List PRs| G[List pull requests]
  E -->|Show config| H[Display current configuration]

  D --> I{Command}
  I -->|pr-review| F
  I -->|list-prs| G

  F --> J[Load and validate config]
  J --> K[Initialize TFS client]
  K --> L{PR ID provided?}
  L -->|No| M[Fetch active PRs and select one]
  L -->|Yes| N[Use provided PR ID]
  M --> O[Get PR details]
  N --> O
  O --> P[Get PR diff or full changed-file context]
  P --> Q[Filter by allowed file extensions]
  Q --> R[Keep additions only]
  R --> S[Limit files with max_diff_files]
  S --> T[Build changed-files summary]
  T --> U[Truncate each file with max_diff_lines]
  U --> V[Run AI general review]
  V --> W[Run AI structured comment generation]
  W --> X[Preview review and suggested comments]
  X --> Y{Dry-run enabled?}
  Y -->|Yes| Z[Stop after preview]
  Y -->|No| AA{Auto-post enabled?}
  AA -->|Yes| AB[Post all review comments]
  AA -->|No| AC[Select comments to post]
  AC --> AB
  AB --> AD[Post general PR summary]
  AD --> AE{Output file configured?}
  AE -->|Yes| AF[Save formatted review output]
  AE -->|No| AG[Finish]
  AF --> AG

  G --> AH[Fetch PR list with filters]
  AH --> AI[Display PR list]

Supported Commands and Options

pr-review

 ai-review pr-review pr-review [pr_id]

Options:

  • --repo-name, -r
  • --dry-run
  • --auto-post
  • --author
  • --target-branch
  • --quick / --detailed / --security
  • --review-scope {diff_only,full_code} (default: diff_only)
  • --max-diff-files N — overrides review.max_diff_files from config.yaml
  • --context, -c
  • --format {terminal,markdown,json}
  • --output, -o
  • --no-color
  • --model, -m
  • --provider, -p
  • --config

list-prs

 ai-review pr-review list-prs

Options:

  • --repo-name, -r
  • --status {active,completed,abandoned,all}
  • --author

Available VS Code Tasks

  • AI Review: Pull Request (Interactive)
  • AI Review: PR (Dry-Run)
  • AI Review: List Active PRs
  • AI Review: Interactive Mode

Troubleshooting

TLS/SSL Error in On-Prem TFS

Prefer using a CA bundle:

tfs:
  verify_ssl: true
  ca_bundle: C:/certs/corporate-root-ca.pem

Avoid verify_ssl: false except for temporary troubleshooting.

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.3.3.tar.gz (68.2 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.3.3-py3-none-any.whl (49.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: code_review_ai_cli-1.3.3.tar.gz
  • Upload date:
  • Size: 68.2 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.3.3.tar.gz
Algorithm Hash digest
SHA256 adb72da34d6d25ee7a0bb4e75f051c56d616c3d27248ae041d3a60875bbaf512
MD5 2da75b5cb9867751c7d2cdff621b515f
BLAKE2b-256 5cfa36984120498d5b8043291769fcde475c0a4b4106697eef9113778c87576d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for code_review_ai_cli-1.3.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d0e410c968bd5fdccc5e308bcae8042fa10c64c5afa73a87f48dc1aa146ffda9
MD5 af7da5861bcf8538521dc6f6d5d85fa5
BLAKE2b-256 9d3aa19b0664104c75c6b4691db01cc49bd7f97744f1a58d9662cea481d109bf

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