Skip to main content

Multi-Agent Code Review Tool

Project description

Logo

๐Ÿ” Codetective - Multi-Agent Code Review Tool

A comprehensive code analysis tool that combines multiple scanning engines (SemGrep, Trivy, AI) with automated fixing capabilities using LangGraph orchestration.

video

Youtube Video

Features

  • Multi-Agent Scanning: Combines SemGrep, Trivy, and AI-powered analysis
  • Automated Fixing: AI-powered code fixes and explanatory comments
  • CLI Interface: Command-line interface for automation and CI/CD integration
  • Web GUI: Modern web interface with NiceGUI
  • LangGraph Orchestration: Intelligent agent coordination and workflow management
  • Smart Comment Generation: Concise TODO comments under 100 words
  • Intelligent Issue Filtering: Removes fixed issues from GUI automatically
  • Configurable: Flexible configuration via files and environment variables

Installation

Prerequisites

Before installing Codetective, ensure you have the following tools installed:

  1. Python 3.10+
  2. SemGrep (optional but recommended):
    pip install semgrep
    
  3. Trivy (optional but recommended):
  4. Ollama (optional, for AI features):

Install Codetective

# Clone the repository
git clone https://github.com/codetective/codetective.git
cd codetective

# Install the package
pip install -e .
# OR
make install

# Or install from PyPI
pip install codetective

Quick Start

1. Check System Compatibility

ollama start
codetective info

This will show you which tools are available and their versions.

codetective_info

2. Run a Code Scan

# Scan current directory with all agents
codetective scan .

# Scan specific paths with selected agents
codetective scan /path/to/code --agents semgrep,trivy --timeout 600

# Custom output file
codetective scan . --output my_scan_results.json

vulnerable_script_py

codetective_scan

3. Apply Fixes

# Apply automatic fixes
codetective fix codetective_scan_results.json

codetective_fix

fixed_vulnerable_script_py

# Add explanatory comments instead
codetective fix codetective_scan_results.json --agent comment

codetective_comment

commented_vulnerable_script_py

4. Launch Web GUI

# Launch NiceGUI interface (default)
codetective gui

# Custom host and port
codetective gui --host 0.0.0.0 --port 7891

Then open your browser to http://localhost:7891 (NiceGUI)

Codetective GUI

CLI Commands

codetective info

Check system compatibility and tool availability.

codetective scan [paths]

Execute multi-agent code scanning.

Options:

  • -a, --agents: Comma-separated agents (semgrep,trivy,ai_review)
  • -t, --timeout: Timeout in seconds (default: 900)
  • -o, --output: Output JSON file (default: codetective_scan_results.json)

Examples:

codetective scan .
codetective scan src/ tests/ --agents semgrep,trivy --timeout 600
codetective scan . --output security_scan.json

codetective fix <json_file>

Apply automated fixes to identified issues.

Options:

  • -a, --agent: Fix agent (comment,edit) (default: edit)
  • --keep-backup: Keep backup files after fix completion
  • --selected-issues: Comma-separated list of issue IDs to fix

Examples:

codetective fix scan_results.json
codetective fix scan_results.json --agent comment

Web GUI Usage

Codetective offers a modern web interface:

NiceGUI Interface (Default)

A modern, responsive web interface with better state management and real-time updates.

1. Project Selection

  • Enter or browse to your project path
  • Select which agents to run
  • Configure scan timeout
  • Start the scanning process

2. Scan Results

  • View results in tabbed interface (one tab per agent)
  • See detailed issue information
  • Select issues for fixing
  • Export results

3. Fix Application

  • Choose fix strategy (edit or comment)
  • Configure backup options and keep-backup settings
  • Select specific issues to fix or use "Select All"
  • Apply fixes with progress tracking and button state management
  • View fix results and modified files
  • Fixed issues are automatically removed from the GUI
  • Real-time progress updates with disabled button during operations

JSON Output Format

Codetective always outputs results in a standardized JSON format:

{
  "timestamp": "2024-01-01T12:00:00",
  "scan_path": "/path/to/project",
  "semgrep_results": [
    {
      "id": "semgrep-rule-file-line",
      "title": "Issue title",
      "description": "Detailed description",
      "severity": "high",
      "file_path": "/path/to/file.py",
      "line_number": 42,
      "rule_id": "rule.id",
      "fix_suggestion": "Suggested fix",
      "status": "detected"
    }
  ],
  "trivy_results": [...],
  "ai_review_results": [...],
  "total_issues": 15,
  "scan_duration": 45.2
}

Agent Types

Scan Agents

  • SemGrep Agent: Static analysis using SemGrep rules
  • Trivy Agent: Security vulnerability and misconfiguration scanning
  • AI Review Agent: Intelligent code review using Ollama

Output Agents

  • Comment Agent: Generates concise TODO comments (under 100 words) for issues
    • Handles None/empty line numbers by adding comments at file beginning
    • Processes multiple issues in same file with proper line number tracking
    • Ignores existing comments when generating new explanations
  • Edit Agent: Automatically applies code fixes
    • Focuses only on actual security vulnerabilities, not influenced by existing comments
    • Maintains original code structure and functionality

Architecture

Codetective uses a multi-agent architecture orchestrated by LangGraph:

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   CLI/GUI       โ”‚     โ”‚   Orchestrator   โ”‚     โ”‚   Config        โ”‚
โ”‚   Interface     โ”‚โ”€โ”€โ”€โ–ถโ”‚   (LangGraph)     โ”‚โ—€โ”€โ”€โ”€โ”‚   Management    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                โ”‚
                โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                โ”‚               โ”‚               โ”‚
        โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
        โ”‚ Scan Agents  โ”‚ โ”‚Output Agentsโ”‚ โ”‚   Utils      โ”‚
        โ”‚              โ”‚ โ”‚             โ”‚ โ”‚              โ”‚
        โ”‚ โ€ข SemGrep    โ”‚ โ”‚ โ€ข Comment   โ”‚ โ”‚ โ€ข File I/O   โ”‚
        โ”‚ โ€ข Trivy      โ”‚ โ”‚ โ€ข Edit      โ”‚ โ”‚ โ€ข Validation โ”‚
        โ”‚ โ€ข AI Review  โ”‚ โ”‚             โ”‚ โ”‚ โ€ข System     โ”‚
        โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Contributing

Contributions to the Codetective are welcome. Follow the CONTRIBUTING.md for contribution guidelines.

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

License

This application is open-source and is released under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License. See the LICENSE file for details.

Shield: CC BY-NC-SA 4.0

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

CC BY-NC-SA 4.0

Acknowledgments

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

codetective-0.1.0b1.tar.gz (53.0 kB view details)

Uploaded Source

Built Distribution

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

codetective-0.1.0b1-py3-none-any.whl (58.9 kB view details)

Uploaded Python 3

File details

Details for the file codetective-0.1.0b1.tar.gz.

File metadata

  • Download URL: codetective-0.1.0b1.tar.gz
  • Upload date:
  • Size: 53.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for codetective-0.1.0b1.tar.gz
Algorithm Hash digest
SHA256 5f5d1cbfe91b7ffee3c6f2a5f1d835c7368adbaeb527dc5e952cbded5dca2dd2
MD5 3b4f6c2ee889eb16b174547909ab3569
BLAKE2b-256 b93592aaaae4b53822cb1ccf35462768de05e326c52584ca0d9871fb6fdf6533

See more details on using hashes here.

File details

Details for the file codetective-0.1.0b1-py3-none-any.whl.

File metadata

  • Download URL: codetective-0.1.0b1-py3-none-any.whl
  • Upload date:
  • Size: 58.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.10

File hashes

Hashes for codetective-0.1.0b1-py3-none-any.whl
Algorithm Hash digest
SHA256 7aee9fcd5054e7f401c83c0e4069bb43ff7c058e4f5c17f05b4bc432c675c7c4
MD5 ab5c6ec7c9730fc23dc251b0725c4cab
BLAKE2b-256 74ed732a8fa7a24c76694b01c53b787871f3b51683466d9629635ffcdebe8ab9

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