Skip to content
dooodledadPublic

About

Precision-first AI code review — run locally, deploy anywhere. BYOK, local-first, open source.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Pascal

Precision-first AI code review — run locally, deploy anywhere

License


Pascal is an open-source AI code review agent that runs on your infrastructure — hooked to your local model (Ollama, vLLM, llama.cpp) or any BYOK provider (OpenRouter, OpenAI, Anthropic, NVIDIA NIM, Nous, Google). It posts review comments directly to GitHub PRs via a GitHub App, with a precision-first approach that minimizes noise while catching real issues.

Why Pascal?

Feature Pascal
Local-first Run on your GPU via http://localhost:8080/v1 — zero API costs, zero data leaves your machine
BYOK Bring your own keys: OpenRouter, OpenAI, Anthropic, NVIDIA, Nous, Google
GitHub native Real GitHub App — posts inline comments, respects your repo permissions
Precision gates Confidence thresholds, category-aware filtering, spend caps per review
Deploy anywhere Single Docker image: docker run -e ... pascal — webhook server + worker in one container
Open source MIT licensed — audit, extend, self-host

Quick Start

1. Prerequisites

  • Python 3.12+
  • A GitHub App with Pull requests: Read & Write, Contents: Read, Webhooks: Active
  • A local model server (Ollama, vLLM, llama.cpp) on http://localhost:8765/v1 or an API key for a remote provider

2. Install

git clone https://github.com/dooodledad/Pascal.git
cd Pascal
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
cp .env.example .env

3. Configure .env

# Required for GitHub delivery
GITHUB_APP_ID=123456
GITHUB_APP_PRIVATE_KEY_PATH=/path/to/private-key.pem
GITHUB_WEBHOOK_SECRET=your-webhook-secret
REVIEW_MAX_REVIEW_COST_USD=0.50
REVIEW_MAX_COMPLETION_TOKENS=2048

# Local model (Ollama, vLLM, llama.cpp on port 8080)
LOCAL_API_KEY=your-local-key
REVIEW_MODEL=auto          # or pin a specific model id

# Remote providers (pick one or more)
OPENROUTER_API_KEY=sk-or-...
NVIDIA_API_KEY=...
NOUS_API_KEY=...

4. Run the Webhook Server

unset PYTHONPATH
python -m delivery.server
# Listens on http://127.0.0.1:8765/github/webhook

5. Run the Worker (separate terminal)

unset PYTHONPATH
python -m delivery.worker --once   # process one job and exit
# or omit --once to poll continuously

6. Deploy with Docker (one command)

docker build -t pascal .
docker run -d \
  -e GITHUB_APP_ID=123456 \
  -e GITHUB_APP_PRIVATE_KEY_PATH=/app/private-key.pem \
  -e GITHUB_WEBHOOK_SECRET=your-webhook-secret \
  -e REVIEW_MAX_REVIEW_COST_USD=0.50 \
  -e REVIEW_MAX_COMPLETION_TOKENS=2048 \
  -e LOCAL_API_KEY=your-local-key \
  -v /host/path/to/key.pem:/app/private-key.pem:ro \
  -v pascal-data:/app/data \
  -p 8765:8765 \
  pascal

GitHub App Setup (detailed)

To have a fully working end-to-end review system, create and configure a GitHub App:

1. Create the GitHub App

  1. Go to Settings → Developer settings → GitHub Apps → New GitHub App
  2. GitHub App name: e.g., pascal-code-review (must be unique)
  3. Homepage URL: your repo URL (e.g., https://github.com/dooodledad/Pascal)
  4. Webhook: Active ✓
    • Webhook URL: https://<your-domain>/github/webhook (or use ngrok for local testing: https://<ngrok-id>.ngrok.io/github/webhook)
    • Webhook secret: generate a random string (store in .env as GITHUB_WEBHOOK_SECRET)
  5. Permissions (Repository permissions):
    • Pull requests: Read & write
    • Contents: Read
    • Commit statuses: Read & write (optional, for status feedback)
    • Issues: Read & write (optional, for future conversational features)
    • Metadata: Read (auto-granted)
  6. Subscribe to events (Repository events):
    • Pull request ✓
    • Issue comment ✓ (for future conversational commands like @pascal review)
  7. Where can this GitHub App be installed?: Any account (or specific org)
  8. Click Create GitHub App

2. Generate Private Key

  1. After creation, scroll to Private keys → Generate a private key
  2. Save the .pem file securely (e.g., ~/.config/pascal/private-key.pem)
  3. Set path in .env: GITHUB_APP_PRIVATE_KEY_PATH=/path/to/private-key.pem

3. Install the App

  1. In the GitHub App settings, go to Install App
  2. Choose the account/org and repositories where Pascal should review PRs
  3. Note the Installation ID (shown in URL after install: .../installations/<ID>) — not needed in config but useful for debugging

4. Configure Webhook Secret

  • The secret you set in step 1 must match GITHUB_WEBHOOK_SECRET in your .env
  • Used to verify X-Hub-Signature-256 on every webhook payload

5. Local Testing with ngrok

# Terminal 1: start ngrok tunnel to your local server
ngrok http 8765

# Terminal 2: run the webhook server
unset PYTHONPATH
python -m delivery.server
# Listens on http://127.0.0.1:8765/github/webhook
  • Copy the ngrok HTTPS URL (e.g., https://abc123.ngrok.io) and update the GitHub App's Webhook URL to https://abc123.ngrok.io/github/webhook

6. Verify End-to-End

  1. Open a PR in a repo where the app is installed
  2. Watch the webhook server logs: you should see webhook ... queued job=...
  3. Run the worker: python -m delivery.worker --once
  4. Check the PR: Pascal should post a review (dry-run by default, set REVIEW_DRY_RUN=false for live)

Dry-run vs Live Mode

  • Dry-run (default): fetches PR, reviews, stores result, does not post to GitHub
  • Live: set REVIEW_DRY_RUN=false in .env → posts inline comments (or APPROVE on clean PRs)

Webhook Events Handled

Event Action Description
pull_request opened, reopened, synchronize, ready_for_review Queues a review
issue_comment created Future: @pascal review / @pascal explain <n> commands

Production Deployment Checklist

  • GitHub App created with correct permissions
  • Private key stored securely (not in repo)
  • Webhook URL points to production server (HTTPS)
  • Webhook secret matches .env
  • REVIEW_DRY_RUN=false for live reviews
  • Server runs behind reverse proxy (nginx/Traefik) with TLS
  • Worker runs continuously (python -m delivery.worker without --once)
  • Monitoring: watch delivery.sqlite3 size, worker logs

Architecture

┌─────────────────────────────────────────────────────────────────┐
│                        GitHub Webhook                            │
└──────────────────────────┬──────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────────────┐
│                   delivery/server (HTTP)                         │
│   • Verifies X-Hub-Signature-256                                 │
│   • Durable queue (SQLite)                                       │
└──────────────────────────┬──────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────────────┐
│                   delivery/worker (queue consumer)               │
│   • Leases jobs, enforces budget                                 │
│   • Fetches PR via GitHub App                                    │
│   • Calls engine.reviewer                                        │
└──────────────────────────┬──────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────────────┐
│                        engine/                                   │
│   • Routes to provider (OpenRouter, local, NVIDIA, Nous, ...)   │
│   • Precision gate (confidence, category thresholds)            │
│   • Spend attestation per review                                 │
└──────────────────────────┬──────────────────────────────────────┘
                           │
                           ▼
┌─────────────────────────────────────────────────────────────────┐
│                      GitHub Review API                           │
│   • Posts inline comments (dry-run by default)                   │
└─────────────────────────────────────────────────────────────────┘

Each review call returns an object envelope: a short PR summary (written at the top of the review body) plus the findings. Findings that fix on a single added line carry a GitHub suggestion block you can apply in one click.

Model Routing

Pascal uses a route chain — each entry in engine/config.py:ROUTES defines a provider endpoint, model(s), and the environment variable that must be set for the route to be active. A route without its key is skipped entirely (never invented, never billed).

RouteSpec("local",     "http://localhost:8765/v1", "auto", "LOCAL_API_KEY"),
RouteSpec("openrouter","https://openrouter.ai/api/v1", [...], "OPENROUTER_API_KEY"),
RouteSpec("nvidia",    "https://integrate.api.nvidia.com/v1", "z-ai/glm-5.3-flash", "NVIDIA_API_KEY"),

Selection priority:

  1. REVIEW_BASE_URL + REVIEW_API_KEY → explicit single route (experiment hatch)
  2. REVIEW_MODEL → matches any model id inside a route, promotes that route
  3. Default → first keyed route in chain order

Cost guardrail: REVIEW_MAX_BLENDED_RATE (default $0.30/Mtok) — routes whose cheapest eligible endpoint exceeds this refuse and fall through. Only enforced where a pricing catalog exists (OpenRouter).

Configuration

Variable Default Description
REVIEW_MODEL — Pin a model id from the route chain
REVIEW_BASE_URL — Explicit route override (experiment hatch)
REVIEW_API_KEY — Key for explicit route
REVIEW_MIN_CONFIDENCE 0.7 Gate threshold (0–1)
REVIEW_ALLOW_NITS false Allow nit-picking comments
REVIEW_REPO_CONTEXT false Fetch surrounding source of changed files (contents API, head SHA) as prompt context
REVIEW_MAX_BLENDED_RATE 0.3 $/Mtok cap (OpenRouter only)
REVIEW_BATCH_WAIT_S 1800 Batch timeout seconds
REVIEW_MAX_REVIEW_COST_USD — Hard cap per review (worker)
REVIEW_MAX_COMPLETION_TOKENS — Max output tokens (worker)
GITHUB_WEBHOOK_HOST 127.0.0.1 Webhook bind address
GITHUB_WEBHOOK_PORT 8765 Webhook port
REVIEW_DELIVERY_DB data/delivery.sqlite3 SQLite ledger path

Local Model Setup

Any OpenAI-compatible server on http://localhost:8080/v1 works:

  • Ollama: ollama serve (runs on 11434; use ollama serve --port 8080 or proxy)
  • vLLM: vllm serve <model> --port 8080
  • llama.cpp: ./server -m model.gguf --port 8080

Set LOCAL_API_KEY in .env (any non-empty string) and REVIEW_MODEL=auto. In Docker, use REVIEW_BASE_URL=http://host.docker.internal:8080/v1 to reach the host model.

Development

# Run tests
unset PYTHONPATH
.venv/bin/python -m pytest -q

# Run a single review against a local PR record
.venv/bin/python -m scripts.simple_review <pr.jsonl>

Project Structure

pascal/
├── engine/           # Core review pipeline
│   ├── config.py     # Routes, settings, env loading
│   ├── client.py     # Provider routing, spend attestation
│   ├── reviewer.py   # Prompt → model → gate → comments
│   ├── prompt.py     # System prompts (v6, v11, v14, v15...)
│   └── providers.py  # OpenRouter catalog, pricing, pins
├── delivery/         # GitHub App webhook + worker
│   ├── server.py     # HTTP webhook ingress
│   ├── worker.py     # Queue consumer, dry-run review
│   ├── github.py     # GitHub App auth, PR fetch, review post
│   ├── store.py      # SQLite queue, leases, spend ledger
│   └── entrypoint.sh # Docker: server (bg) + worker (fg)
├── scripts/          # simple_review: one-off local review runner
└── tests/            # Unit + integration tests

Contributing

  1. Fork → branch → PR
  2. All changes pass /review loop (independent reviewer, zero findings)
  3. Tests green: pytest -q
  4. No secrets committed (.env is gitignored)

License

MIT — see LICENSE.

Community


Built with precision. Deployed with confidence.

About

Precision-first AI code review — run locally, deploy anywhere. BYOK, local-first, open source.

Topics

Resources

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Used by

Contributors

Languages