Skip to main content

An intelligent code review detective powered by LLM - solving code mysteries, one PR at a time

Project description

🔍 Detective Benno

Python Version OpenAI License GitHub Actions

"Every line of code tells a story. I find the plot holes." - Detective Benno

An intelligent code review detective powered by LLM that investigates your pull requests and uncovers bugs, security vulnerabilities, and code smells before they become problems.

Features

  • Automated PR Investigation - Automatically triggered on pull request events
  • Multi-language Support - Investigates Python, Go, JavaScript, TypeScript, Rust, and more
  • Configurable Rules - Define custom investigation guidelines per repository
  • GitHub Action - Easy integration with existing CI/CD pipelines
  • CLI Tool - Investigate local changes before committing
  • Diff-aware Analysis - Only investigates changed code, not entire files

Quick Start

Installation

pip install detective-benno

CLI Usage

# Investigate staged changes
benno investigate --staged

# Investigate specific files
benno investigate src/main.py src/utils.py

# Investigate a git diff
git diff main..feature | benno investigate --diff

# Investigate with custom guidelines
benno investigate --config .benno.yaml

GitHub Action

Add to your .github/workflows/detective-benno.yml:

name: Detective Benno Investigation

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  investigate:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write

    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Detective Benno Investigation
        uses: bimakw/detective-benno@v1
        with:
          openai_api_key: ${{ secrets.OPENAI_API_KEY }}
          github_token: ${{ secrets.GITHUB_TOKEN }}
          investigation_level: detailed  # minimal, standard, detailed

Configuration

Create .benno.yaml in your repository root:

# Detective Benno Configuration
version: "1"

# Investigation settings
investigation:
  level: detailed          # minimal, standard, detailed
  max_findings: 10         # Maximum findings per investigation
  languages:               # Language-specific settings
    python:
      style_guide: pep8
      check_types: true
    go:
      style_guide: effective-go
    javascript:
      style_guide: airbnb

# Custom investigation guidelines
guidelines:
  - "Look for potential SQL injection vulnerabilities"
  - "Check for hardcoded credentials or secrets"
  - "Verify error handling is comprehensive"
  - "Ensure all functions have proper documentation"

# Ignore patterns
ignore:
  files:
    - "*.md"
    - "*.txt"
    - "vendor/**"
    - "node_modules/**"
  patterns:
    - "TODO:"  # Don't flag TODOs

# Model settings
model:
  provider: openai
  name: gpt-4o
  temperature: 0.3

Investigation Categories

Detective Benno investigates for:

Category Description
Security SQL injection, XSS, hardcoded secrets, unsafe operations
Performance N+1 queries, unnecessary loops, memory leaks
Best Practices Code style, naming conventions, design patterns
Error Handling Missing try-catch, unhandled promises, panic recovery
Maintainability Code duplication, complexity, documentation

Example Investigation Report

============================================
   DETECTIVE BENNO - INVESTIGATION REPORT
============================================

Case #: PR-142
Files Investigated: 3
Findings: 5 (2 critical, 2 warnings, 1 suggestion)

CRITICAL FINDINGS
-----------------

Location: src/auth.py:45
Evidence:
   query = f"SELECT * FROM users WHERE id = {user_id}"

Finding: Potential SQL injection vulnerability
Recommendation: Use parameterized queries instead:
   query = "SELECT * FROM users WHERE id = %s"
   cursor.execute(query, (user_id,))

WARNINGS
--------

Location: src/api.py:128
Finding: Function `process_data` exceeds 50 lines
Recommendation: Consider breaking into smaller functions

============================================
Case Status: REQUIRES ATTENTION
============================================

Environment Variables

Variable Required Description
OPENAI_API_KEY Yes Your OpenAI API key
GITHUB_TOKEN For PR investigations GitHub token with PR write access
BENNO_CONFIG No Path to custom config file

Development

# Clone repository
git clone https://github.com/bimakw/detective-benno.git
cd detective-benno

# Create virtual environment
python -m venv venv
source venv/bin/activate  # Linux/Mac
# or: venv\Scripts\activate  # Windows

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

# Run linting
ruff check .
mypy src/

Why "Detective Benno"?

Every codebase has mysteries waiting to be solved - bugs hiding in plain sight, security vulnerabilities lurking in the shadows, and performance bottlenecks slowing everything down. Detective Benno is your tireless investigator, examining every line of code to uncover issues before they become problems.

Contributing

Contributions are welcome! Please read our Contributing Guide for details.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

Acknowledgments

  • OpenAI for GPT-4 API
  • GitHub Actions for CI/CD integration
  • The open source community

Detective Benno - Solving code mysteries, one PR at a time
Made with code by Bima Kharisma Wicaksana

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

detective_benno-0.1.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

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

detective_benno-0.1.0-py3-none-any.whl (18.3 kB view details)

Uploaded Python 3

File details

Details for the file detective_benno-0.1.0.tar.gz.

File metadata

  • Download URL: detective_benno-0.1.0.tar.gz
  • Upload date:
  • Size: 16.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for detective_benno-0.1.0.tar.gz
Algorithm Hash digest
SHA256 be2febc5bf07c1e5a8a8178fd6ba91547de929ed44e9ed704e1b7685d7c5b6c2
MD5 acc95032d4fc133d90f7725f08f3e691
BLAKE2b-256 597f46e1120c366293d638576974221d83ebebf7ebb9c72e69b0744006aa2594

See more details on using hashes here.

File details

Details for the file detective_benno-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for detective_benno-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1b45874f3a36ba1a958a02faf43b4d216cb966cc5efa2ffd7102ae258bbad219
MD5 09b9035c353947c4074c7a1eee3a7510
BLAKE2b-256 249b188971f736806248e73a4b45c2217b0146a3c911cdfeb211291924378491

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