gavel

module
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2026 License: MIT

README

Gavel

AI code review that catches what linters miss — security holes, ignored errors, risky patterns — and gates your CI pipeline automatically.

What You Get

Run Gavel on your code and get findings like this:

{
  "decision": "reject",
  "reason": "Decision: reject based on 2 findings",
  "relevant_findings": [
    {
      "ruleId": "S3649",
      "level": "error",
      "message": {
        "text": "SQL injection: raw user input interpolated into query via fmt.Sprintf"
      },
      "properties": {
        "gavel/confidence": 0.95,
        "gavel/explanation": "The function builds a SQL query using fmt.Sprintf with user-supplied input directly interpolated, allowing SQL injection.",
        "gavel/recommendation": "Use parameterized queries with placeholder arguments instead of string interpolation."
      }
    }
  ]
}

Every finding includes a confidence score, an explanation of why it's a problem, and a concrete recommendation to fix it.

Why Gavel

  • Catches real bugs. Not just style nits. Security vulnerabilities, ignored errors, risky patterns, overly complex code. Gavel understands context — it knows when user input flows into a SQL query, not just that a query exists.
  • Gates CI automatically. Every PR gets a verdict: merge, reject, or review. Findings appear as native GitHub annotations. High-confidence issues block the merge; everything else goes to human review.
  • Works with any LLM. Run free and local with Ollama, or use OpenRouter, Anthropic, AWS Bedrock, or OpenAI. Switch models per environment — fast/cheap in CI, thorough for releases.

Quick Start

# Install (see https://github.com/chris-regnier/gavel/releases for latest version)
VERSION=v0.2.0
curl -L "https://github.com/chris-regnier/gavel/releases/download/${VERSION}/gavel_${VERSION}_Darwin_arm64.tar.gz" | tar xz
sudo mv gavel_Darwin_arm64 /usr/local/bin/gavel

# Set up a provider (pick one)
export OPENROUTER_API_KEY=sk-or-...          # Cloud: fast, pay-per-use
# OR: ollama pull qwen2.5-coder:7b           # Local: free, private

# Generate a config from a description of your project
gavel create config "Go REST API with PostgreSQL"

# Analyze and judge
gavel analyze --dir ./src
gavel judge

See the full quickstart for detailed setup.

What It Catches

Category Example Finding Rule
Security SQL injection via string concatenation S3649
Security Hardcoded API keys and passwords S2068
Security OS command injection from user input S2076
Reliability Error return value silently ignored S1086
Reliability Empty error handler (if err != nil {}) AST003
Maintainability Function exceeds 50 lines AST001
Maintainability Nesting depth exceeds 4 levels AST002

19 built-in rules (regex + tree-sitter AST) run instantly with no LLM call. The LLM finds deeper issues that pattern matching can't.

How It Works

analyze: Source Code → LLM Analyzer → SARIF Output → Results Store
           (files,       (AI finds        (standard        (findings
            diffs,        real bugs)       format)          saved)
            dirs)

judge:   Results Store → Rego Evaluator → Verdict
           (reads           (policy-based     (merge,
            findings)        gating)           reject,
                                               review)

Gavel produces standard SARIF 2.1.0 output that integrates with GitHub Code Scanning, VS Code, and any SARIF-compatible tool.

Documentation

Full docs at chris-regnier.github.io/gavel.

Guides

Development

task build           # Build the binary
task test            # Run all tests
task lint            # Run go vet
task generate        # Regenerate BAML client from baml_src/

See the contributing guide.

License

MIT

Directories

Path Synopsis
benchmarks
cmd
gavel command
cmd/gavel/serve.go
cmd/gavel/serve.go
gavel-bench command
internal
cache
internal/cache/local.go
internal/cache/local.go
calibration/server
Package server provides the HTTP API for the online calibration subsystem.
Package server provides the HTTP API for the online calibration subsystem.
lsp
internal/lsp/analyzer.go
internal/lsp/analyzer.go
mcp
Package mcp implements a Model Context Protocol server for Gavel, exposing code analysis capabilities as MCP tools, resources, and prompts.
Package mcp implements a Model Context Protocol server for Gavel, exposing code analysis capabilities as MCP tools, resources, and prompts.
output
Package output provides formatters for rendering Gavel analysis results in different output formats (JSON, SARIF, Markdown, pretty terminal).
Package output provides formatters for rendering Gavel analysis results in different output formats (JSON, SARIF, Markdown, pretty terminal).
server
internal/server/handlers.go
internal/server/handlers.go
server/middleware
internal/server/middleware/auth.go
internal/server/middleware/auth.go
service
internal/service/judge.go
internal/service/judge.go

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL