Skip to content

Vilin97/botbaki

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Botbaki - AI Code Review for GitHub PRs

AI-powered code review bot for GitHub pull requests, deployed as a GitHub App with inline review comments.

Features

  • Inline review comments: Posts GitHub PR reviews with comments on specific lines
  • Mathlib4-aware: Reviews check style, naming conventions, and mathlib-specific patterns
  • Smart caching: Reviews stored and reused for identical PR state + prompt combinations
  • Feedback collection: Users can provide feedback on review quality
  • Polling daemon: Watches for @botbaki triggers every 2 minutes

Bot Identity

Botbaki runs as a GitHub App: botbaki-review[bot]

This provides:

  • Separate identity (not impersonating a user)
  • Higher rate limits (5000+ requests/hour)
  • No abuse detection issues

Commands

Trigger botbaki by commenting on a PR:

Command Description
@botbaki review Generate review with inline comments
@botbaki review --single Post as single comment (no inline)
@botbaki review --diff-only Review without timeline context
@botbaki feedback <text> Provide feedback on the last review
@botbaki help Show available commands

Requirements

  • Python 3.10+
  • GitHub App credentials (for GitHub API access)
  • Anthropic API key (for Claude reviews)

Installation

1. Clone and Install Dependencies

git clone https://github.com/kim-em/botbaki.git
cd botbaki
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

2. Create GitHub App

  1. Go to https://github.com/settings/apps/new (or org settings for org app)
  2. Set permissions:
    • Contents: Read-only
    • Issues: Read and write
    • Pull requests: Read and write
  3. Disable webhooks (we use polling)
  4. Generate and download private key
  5. Install the app on your repository

3. Configure Credentials

mkdir -p ~/.config/botbaki

# GitHub App credentials
echo "YOUR_APP_ID" > ~/.config/botbaki/github-app-id
cp path/to/private-key.pem ~/.config/botbaki/github-app-key.pem
echo "YOUR_INSTALLATION_ID" > ~/.config/botbaki/github-installation-id
chmod 600 ~/.config/botbaki/github-app-key.pem

# Anthropic API key
echo "ANTHROPIC_API_KEY=sk-ant-..." > ~/.config/botbaki/env
chmod 600 ~/.config/botbaki/env

4. Run the Daemon

# Manual run
source .venv/bin/activate
python3 -m src.cli daemon

# Or install as systemd service
cd service && ./install.sh

Usage

CLI Commands

# Generate a review (outputs to stdout)
botbaki review leanprover-community/mathlib4 32904
botbaki review leanprover-community/mathlib4 32904 --diff-only  # No timeline
botbaki review leanprover-community/mathlib4 32904 --force      # Bypass cache

# Sync PR data from GitHub
botbaki sync leanprover-community/mathlib4 --pr 32904           # Single PR
botbaki sync leanprover-community/mathlib4 --incremental        # Changed PRs only
botbaki sync leanprover-community/mathlib4 --since 2026-01-01   # Full sync since date

# List and view PRs
botbaki list leanprover-community/mathlib4 --state open --limit 20
botbaki show leanprover-community/mathlib4 32904

# Search comments (FTS5 syntax)
botbaki search "omega tactic"

# Repository statistics
botbaki stats leanprover-community/mathlib4
botbaki stats leanprover-community/mathlib4 --author kim-em

# Run daemon
botbaki daemon
botbaki daemon --repo leanprover-community/mathlib4 --interval 120

# Check GitHub API rate limit
botbaki rate-limit

Feedback Commands

# Show feedback report (unhandled only, with emoji reactions)
botbaki feedback-report
botbaki feedback-report --all              # Include handled feedback
botbaki feedback-report --since 2026-01-01 # Filter by date
botbaki feedback-report --no-reactions     # Skip fetching reactions from GitHub

# Analyze feedback and generate improved prompt
botbaki analyze-feedback                   # Generate prompts/mathlib4/YYYY-MM-DD.md
botbaki analyze-feedback --dry-run         # Preview without API calls
botbaki analyze-feedback --verbose         # Show progress

# Mark feedback as handled after incorporating into prompts
botbaki mark-feedback-handled
botbaki mark-feedback-handled --dry-run

Daemon Mode

The daemon polls for @botbaki comments every 2 minutes:

botbaki daemon

Management (when installed as systemd service):

sudo systemctl status botbaki   # Check status
sudo systemctl restart botbaki  # Restart
sudo journalctl -u botbaki -f   # Follow logs

Configuration

Credentials

All credentials stored in ~/.config/botbaki/:

File Description
env Anthropic API key (ANTHROPIC_API_KEY=...)
github-app-id GitHub App ID
github-app-key.pem GitHub App private key
github-installation-id Installation ID for target repo
github-app-slug App slug for bot login (optional, defaults to "botbaki")

Prompts

Review prompts are in prompts/{repo}/YYYY-MM-DD.md:

  • Use {diff}, {timeline}, {title}, {author}, etc. as placeholders
  • Reference files in prompts/{repo}/references/ for style guides
  • Latest prompt (by filename) is used by default

Database

SQLite database (data/github_prs.db) contains:

  • pull_requests - PR metadata
  • commits - Commits on PR branches
  • review_comments - Inline code comments
  • issue_comments - General PR discussion
  • reviews - Review submissions
  • pr_reviews - Generated AI reviews (cached)
  • review_feedback - User feedback on reviews
  • processed_triggers - Tracked bot triggers

Architecture

┌─────────────────┐     ┌──────────────┐
│  GitHub         │────▶│  Polling     │
│  (PRs/Comments) │     │  Daemon      │
└─────────────────┘     └──────┬───────┘
                               │
                               ▼
                        ┌──────────────┐
                        │  Trigger     │
                        │  Processing  │
                        └──────┬───────┘
                               │
              ┌────────────────┼────────────────┐
              ▼                ▼                ▼
       ┌──────────┐     ┌──────────┐     ┌──────────┐
       │ SQLite   │     │ Claude   │     │ GitHub   │
       │ Database │     │ API      │     │ API      │
       └──────────┘     └──────────┘     └──────────┘
                                         (PyGithub)

Key modules:

  • src/cli.py - Command-line interface
  • src/daemon.py - Polling daemon
  • src/review.py - AI review generation with structured output
  • src/analysis.py - Feedback analysis and prompt improvement
  • src/github_client.py - GitHub App authentication via PyGithub
  • src/sync.py - PR data synchronization
  • src/database.py - SQLite operations

Deployment

Currently deployed to chonk.lean-fro.org:

# SSH to chonk
ssh chonk

# Check status
sudo systemctl status botbaki
sudo journalctl -u botbaki -f

# Deploy updates
cd ~/projects/botbaki
git pull
sudo systemctl restart botbaki

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 98.6%
  • Shell 1.4%