GitHub - Gentleman-Programming/gentleman-guardian-angel: ๐Ÿ˜‡ Gentleman Guardian Angel (gga) - Provider-agnostic code review using AI. Use Claude, Gemini, Codex, Ollama to enforce your coding standards.

15 min read Original article โ†—

Version License Bash Homebrew Tests PRs Welcome

๐Ÿค– Gentleman Guardian Angel

Provider-agnostic code review using AI
Use Claude, Gemini, Codex, Ollama, or any AI to enforce your coding standards.
Zero dependencies. Pure Bash. Works everywhere.

Installation โ€ข Quick Start โ€ข Providers โ€ข Commands โ€ข Configuration โ€ข Caching โ€ข Development


Example

image

๐ŸŽฏ Why?

You have coding standards. Your team ignores them. Code reviews catch issues too late.

Gentleman Guardian Angel runs on every commit, validating your staged files against your project's AGENTS.md (or any rules file). It's like having a senior developer review every line before it hits the repo.

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   git commit    โ”‚ โ”€โ”€โ–ถ โ”‚  AI Review   โ”‚ โ”€โ”€โ–ถ โ”‚  โœ… Pass/Fail   โ”‚
โ”‚  (staged files) โ”‚     โ”‚  (any LLM)   โ”‚     โ”‚  (with details) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Key features:

  • ๐Ÿ”Œ Provider agnostic - Use whatever AI you have installed
  • ๐Ÿ“ฆ Zero dependencies - Pure Bash, no Node/Python/Go required
  • ๐Ÿช Git native - Installs as a standard pre-commit hook
  • โš™๏ธ Highly configurable - File patterns, exclusions, custom rules
  • ๐Ÿšจ Strict mode - Fail CI on ambiguous responses
  • โšก Smart caching - Skip unchanged files for faster reviews
  • ๐Ÿบ Homebrew ready - One command install

๐Ÿ“ฆ Installation

Homebrew (Recommended) ๐Ÿบ

brew tap gentleman-programming/tap
brew install gga

Or in a single command:

brew install gentleman-programming/tap/gga

Manual Installation

git clone https://github.com/Gentleman-Programming/gentleman-guardian-angel.git
cd gga
./install.sh

Verify Installation

gga version
# Output: gga v2.2.0

๐Ÿš€ Quick Start

# 1. Go to your project
cd ~/your-project

# 2. Initialize config
gga init

# 3. Create your rules file
touch AGENTS.md  # Add your coding standards

# 4. Install the git hook
gga install

# 5. Done! Now every commit gets reviewed ๐ŸŽ‰

๐ŸŽฌ Real World Example

Let's walk through a complete example from setup to commit:

Step 1: Setup in your project

$ cd ~/projects/my-react-app

$ gga init

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  Gentleman Guardian Angel v2.2.0
  Provider-agnostic code review using AI
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โœ… Created config file: .gga

โ„น๏ธ  Next steps:
  1. Edit .gga to set your preferred provider
  2. Create AGENTS.md with your coding standards
  3. Run: gga install

Step 2: Configure your provider

$ cat .gga

# AI Provider (required)
PROVIDER="claude"

# File patterns to include in review (comma-separated)
FILE_PATTERNS="*.ts,*.tsx,*.js,*.jsx"

# File patterns to exclude from review (comma-separated)
EXCLUDE_PATTERNS="*.test.ts,*.spec.ts,*.test.tsx,*.spec.tsx,*.d.ts"

# File containing code review rules
RULES_FILE="AGENTS.md"

# Strict mode: fail if AI response is ambiguous
STRICT_MODE="true"

Step 3: Create your coding standards

$ cat > AGENTS.md << 'EOF'
# Code Review Rules

## TypeScript
- No `any` types - use proper typing
- Use `const` over `let` when possible
- Prefer interfaces over type aliases for objects

## React  
- Use functional components with hooks
- No `import * as React` - use named imports like `import { useState }`
- All images must have alt text for accessibility

## Styling
- Use Tailwind CSS utilities only
- No inline styles or CSS-in-JS
- No hardcoded colors - use design system tokens
EOF

Step 4: Install the git hook

$ gga install

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  Gentleman Guardian Angel v2.2.0
  Provider-agnostic code review using AI
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โœ… Installed pre-commit hook: /Users/dev/projects/my-react-app/.git/hooks/pre-commit

Step 5: Make some changes and commit

$ git add src/components/Button.tsx
$ git commit -m "feat: add new button component"

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  Gentleman Guardian Angel v2.2.0
  Provider-agnostic code review using AI
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โ„น๏ธ  Provider: claude
โ„น๏ธ  Rules file: AGENTS.md
โ„น๏ธ  File patterns: *.ts,*.tsx,*.js,*.jsx
โ„น๏ธ  Cache: enabled

Files to review:
  - src/components/Button.tsx

โ„น๏ธ  Sending to claude for review...

STATUS: FAILED

Violations found:

1. **src/components/Button.tsx:3** - TypeScript Rule
   - Issue: Using `any` type for props
   - Fix: Define proper interface for ButtonProps

2. **src/components/Button.tsx:15** - React Rule  
   - Issue: Using `import * as React`
   - Fix: Use `import { useState, useCallback } from 'react'`

3. **src/components/Button.tsx:22** - Styling Rule
   - Issue: Hardcoded color `#3b82f6`
   - Fix: Use Tailwind class `bg-blue-500` instead

โŒ CODE REVIEW FAILED

Fix the violations listed above before committing.

Step 6: Fix issues and commit again

$ git add src/components/Button.tsx
$ git commit -m "feat: add new button component"

โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”
  Gentleman Guardian Angel v2.2.0
โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”โ”

โ„น๏ธ  Provider: claude
โ„น๏ธ  Cache: enabled

Files to review:
  - src/components/Button.tsx

โ„น๏ธ  Sending to claude for review...

STATUS: PASSED

All files comply with the coding standards defined in AGENTS.md.

โœ… CODE REVIEW PASSED

[main 4a2b3c1] feat: add new button component
 1 file changed, 45 insertions(+)
 create mode 100644 src/components/Button.tsx

๐Ÿ“‹ Commands

Command Description Example
init Create sample .gga config file gga init
install Install git pre-commit hook in current repo gga install
uninstall Remove git pre-commit hook from current repo gga uninstall
run Run code review on staged files gga run
run --no-cache Run review ignoring cache gga run --no-cache
config Display current configuration and status gga config
cache status Show cache status for current project gga cache status
cache clear Clear cache for current project gga cache clear
cache clear-all Clear all cached data gga cache clear-all
help Show help message with all commands gga help
version Show installed version gga version

Command Details

gga init

Creates a sample .gga configuration file in your project root with sensible defaults.

$ gga init
โœ… Created config file: .gga

gga install

Installs a git pre-commit hook that automatically runs code review on every commit.

$ gga install
โœ… Installed pre-commit hook: .git/hooks/pre-commit

If a pre-commit hook already exists, it will ask if you want to append to it.

gga uninstall

Removes the git pre-commit hook from your repository.

$ gga uninstall
โœ… Removed pre-commit hook

gga run [--no-cache]

Runs code review on currently staged files. Uses intelligent caching by default to skip unchanged files.

$ git add src/components/Button.tsx
$ gga run
# Reviews the staged file (uses cache)

$ gga run --no-cache
# Forces review of all files, ignoring cache

gga config

Shows the current configuration, including where config files are loaded from and all settings.

$ gga config

Current Configuration:

Config Files:
  Global:  Not found
  Project: .gga

Values:
  PROVIDER:          claude
  FILE_PATTERNS:     *.ts,*.tsx,*.js,*.jsx
  EXCLUDE_PATTERNS:  *.test.ts,*.spec.ts
  RULES_FILE:        AGENTS.md
  STRICT_MODE:       true

Rules File: Found

โšก Smart Caching

GGA includes intelligent caching to speed up reviews by skipping files that haven't changed.

How It Works

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        Cache Logic                               โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  1. Hash AGENTS.md + .gga config                                โ”‚
โ”‚     โ””โ”€โ–บ If changed โ†’ Invalidate ALL cache                       โ”‚
โ”‚                                                                  โ”‚
โ”‚  2. For each staged file:                                        โ”‚
โ”‚     โ””โ”€โ–บ Hash file content                                        โ”‚
โ”‚         โ””โ”€โ–บ If hash exists in cache with PASSED โ†’ Skip          โ”‚
โ”‚         โ””โ”€โ–บ If not cached โ†’ Send to AI for review               โ”‚
โ”‚                                                                  โ”‚
โ”‚  3. After PASSED review:                                         โ”‚
โ”‚     โ””โ”€โ–บ Store file hash in cache                                โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Cache Invalidation

The cache automatically invalidates when:

Change Effect
File content changes Only that file is re-reviewed
AGENTS.md changes All files are re-reviewed
.gga config changes All files are re-reviewed

Cache Commands

# Check cache status
$ gga cache status

Cache Status:

  Cache directory: ~/.cache/gga/a1b2c3d4...
  Cache validity: Valid
  Cached files: 12
  Cache size: 4.0K

# Clear project cache
$ gga cache clear
โœ… Cleared cache for current project

# Clear all cache (all projects)
$ gga cache clear-all
โœ… Cleared all cache data

Bypass Cache

# Force review all files, ignoring cache
gga run --no-cache

Cache Location

~/.cache/gga/
โ”œโ”€โ”€ <project-hash-1>/
โ”‚   โ”œโ”€โ”€ metadata          # Hash of AGENTS.md + .gga
โ”‚   โ””โ”€โ”€ files/
โ”‚       โ”œโ”€โ”€ <file-hash-a> # "PASSED"
โ”‚       โ””โ”€โ”€ <file-hash-b> # "PASSED"
โ””โ”€โ”€ <project-hash-2>/
    โ””โ”€โ”€ ...

๐Ÿ”Œ Providers

Use whichever AI CLI you have installed:

Provider Config Value CLI Command Used Installation
Claude claude echo "prompt" | claude --print claude.ai/code
Gemini gemini echo "prompt" | gemini github.com/google-gemini/gemini-cli
Codex codex codex exec "prompt" npm i -g @openai/codex
Ollama ollama:<model> ollama run <model> "prompt" ollama.ai

Provider Examples

# Use Claude (recommended - most reliable)
PROVIDER="claude"

# Use Google Gemini
PROVIDER="gemini"

# Use OpenAI Codex
PROVIDER="codex"

# Use Ollama with Llama 3.2
PROVIDER="ollama:llama3.2"

# Use Ollama with CodeLlama (optimized for code)
PROVIDER="ollama:codellama"

# Use Ollama with Qwen Coder
PROVIDER="ollama:qwen2.5-coder"

# Use Ollama with DeepSeek Coder
PROVIDER="ollama:deepseek-coder"

โš™๏ธ Configuration

Config File: .gga

Create this file in your project root:

# AI Provider (required)
# Options: claude, gemini, codex, ollama:<model>
PROVIDER="claude"

# File patterns to review (comma-separated globs)
# Default: * (all files)
FILE_PATTERNS="*.ts,*.tsx,*.js,*.jsx"

# Patterns to exclude from review (comma-separated globs)
# Default: none
EXCLUDE_PATTERNS="*.test.ts,*.spec.ts,*.d.ts"

# File containing your coding standards
# Default: AGENTS.md
RULES_FILE="AGENTS.md"

# Fail if AI response is ambiguous (recommended for CI)
# Default: true
STRICT_MODE="true"

Configuration Options

Option Required Default Description
PROVIDER โœ… Yes - AI provider to use
FILE_PATTERNS No * Comma-separated file patterns to include
EXCLUDE_PATTERNS No - Comma-separated file patterns to exclude
RULES_FILE No AGENTS.md Path to your coding standards file
STRICT_MODE No true Fail on ambiguous AI responses

Config Hierarchy (Priority Order)

  1. Environment variable GGA_PROVIDER (highest priority)
  2. Project config .gga (in project root)
  3. Global config ~/.config/gga/config (lowest priority)
# Override provider for a single run
GGA_PROVIDER="gemini" gga run

# Or export for the session
export GGA_PROVIDER="ollama:llama3.2"

๐Ÿ“ Rules File (AGENTS.md)

The AI needs to know your standards. Create an AGENTS.md file:

# Code Review Rules

## TypeScript
- Use `const` and `let`, never `var`
- No `any` types - always use proper typing
- Prefer interfaces over type aliases for objects
- Use optional chaining (`?.`) and nullish coalescing (`??`)

## React
- Functional components only, no class components
- No `import * as React` - use named imports
- Use semantic HTML elements
- All images need alt text
- Interactive elements need aria labels

## Styling
- Use Tailwind CSS utilities
- No inline styles
- No hex colors - use design tokens

## Testing
- All new features need tests
- Test files must be co-located with source files
- Use descriptive test names that explain the behavior

๐Ÿ’ก Pro tip: Your AGENTS.md can also serve as documentation for human reviewers!


๐ŸŽจ Project Examples

TypeScript/React Project

# .gga
PROVIDER="claude"
FILE_PATTERNS="*.ts,*.tsx"
EXCLUDE_PATTERNS="*.test.ts,*.test.tsx,*.spec.ts,*.d.ts,*.stories.tsx"
RULES_FILE="AGENTS.md"

Python Project

# .gga
PROVIDER="ollama:codellama"
FILE_PATTERNS="*.py"
EXCLUDE_PATTERNS="*_test.py,test_*.py,conftest.py,__pycache__/*"
RULES_FILE=".coding-standards.md"

Go Project

# .gga
PROVIDER="gemini"
FILE_PATTERNS="*.go"
EXCLUDE_PATTERNS="*_test.go,mock_*.go,*_mock.go"

Full-Stack Monorepo

# .gga
PROVIDER="claude"
FILE_PATTERNS="*.ts,*.tsx,*.py,*.go"
EXCLUDE_PATTERNS="*.test.*,*_test.*,*.mock.*,*.d.ts,dist/*,build/*"

๐Ÿ”„ How It Works

git commit -m "feat: add feature"
    โ”‚
    โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Pre-commit Hook (gga run) โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
    โ”‚
    โ”œโ”€โ”€โ–ถ 1. Load config from .gga
    โ”‚
    โ”œโ”€โ”€โ–ถ 2. Validate provider is installed
    โ”‚
    โ”œโ”€โ”€โ–ถ 3. Check AGENTS.md exists
    โ”‚
    โ”œโ”€โ”€โ–ถ 4. Get staged files matching FILE_PATTERNS
    โ”‚       (excluding EXCLUDE_PATTERNS)
    โ”‚
    โ”œโ”€โ”€โ–ถ 5. Read coding rules from AGENTS.md
    โ”‚
    โ”œโ”€โ”€โ–ถ 6. Build prompt: rules + file contents
    โ”‚
    โ”œโ”€โ”€โ–ถ 7. Send to AI provider (claude/gemini/codex/ollama)
    โ”‚
    โ””โ”€โ”€โ–ถ 8. Parse response
            โ”‚
            โ”œโ”€โ”€ "STATUS: PASSED" โ”€โ”€โ–ถ โœ… Commit proceeds
            โ”‚
            โ””โ”€โ”€ "STATUS: FAILED" โ”€โ”€โ–ถ โŒ Commit blocked
                                       (shows violation details)

๐Ÿšซ Bypass Review

Sometimes you need to commit without review:

# Skip pre-commit hook entirely
git commit --no-verify -m "wip: work in progress"

# Short form
git commit -n -m "hotfix: urgent fix"

๐Ÿ”— Integrations

Gentleman Guardian Angel works standalone with native git hooks, but you can also integrate it with popular hook managers.

Native Git Hook (Default)

This is what gga install does automatically:

# .git/hooks/pre-commit
#!/usr/bin/env bash
gga run || exit 1

Husky (Node.js projects)

Husky is popular in JavaScript/TypeScript projects.

Setup with Husky v9+

# Install husky
npm install -D husky

# Initialize husky
npx husky init

Edit .husky/pre-commit:

#!/usr/bin/env bash

# Run Gentleman Guardian Angel
gga run || exit 1

# Your other checks (optional)
npm run lint
npm run typecheck

With lint-staged (review only staged files)

# Install dependencies
npm install -D husky lint-staged

package.json:

{
  "scripts": {
    "prepare": "husky"
  },
  "lint-staged": {
    "*.{ts,tsx,js,jsx}": [
      "eslint --fix",
      "prettier --write"
    ]
  }
}

.husky/pre-commit:

#!/usr/bin/env bash

# AI Review first (uses git staged files internally)
gga run || exit 1

# Then lint-staged for formatting
npx lint-staged

pre-commit (Python projects)

pre-commit is the standard for Python projects.

Setup

# Install pre-commit
pip install pre-commit

# Or with brew
brew install pre-commit

Create .pre-commit-config.yaml:

repos:
  # Gentleman Guardian Angel (runs first)
  - repo: local
    hooks:
      - id: gga
        name: Gentleman Guardian Angel
        entry: gga run
        language: system
        pass_filenames: false
        stages: [pre-commit]

  # Your other hooks
  - repo: https://github.com/psf/black
    rev: 24.4.2
    hooks:
      - id: black

  - repo: https://github.com/pycqa/flake8
    rev: 7.0.0
    hooks:
      - id: flake8

  - repo: https://github.com/pre-commit/mirrors-mypy
    rev: v1.10.0
    hooks:
      - id: mypy

Install the hooks:

Running manually

# Run all hooks
pre-commit run --all-files

# Run only AI review
pre-commit run gga

Lefthook (Fast, language-agnostic)

Lefthook is a fast Git hooks manager written in Go.

Setup

# Install
brew install lefthook

# Or with npm
npm install -D lefthook

Create lefthook.yml:

pre-commit:
  parallel: false
  commands:
    ai-review:
      run: gga run
      fail_text: "Gentleman Guardian Angel failed. Fix violations before committing."

    lint:
      glob: "*.{ts,tsx,js,jsx}"
      run: npm run lint

    typecheck:
      run: npm run typecheck

Install hooks:

CI/CD Integration

You can also run Gentleman Guardian Angel in your CI pipeline:

GitHub Actions

# .github/workflows/ai-review.yml
name: Gentleman Guardian Angel

on:
  pull_request:
    types: [opened, synchronize]

jobs:
  review:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install Gentleman Guardian Angel
        run: |
          git clone https://github.com/Gentleman-Programming/gentleman-guardian-angel.git /tmp/gga
          chmod +x /tmp/gga/bin/gga
          echo "/tmp/gga/bin" >> $GITHUB_PATH

      - name: Install Claude CLI
        run: |
          # Install your preferred provider CLI
          npm install -g @anthropic-ai/claude-code
        env:
          ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}

      - name: Run AI Review
        run: |
          # Get changed files in PR
          git diff --name-only origin/${{ github.base_ref }}...HEAD > /tmp/changed_files.txt
          
          # Stage them for review
          cat /tmp/changed_files.txt | xargs git add
          
          # Run review
          gga run

GitLab CI

# .gitlab-ci.yml
gga:
  stage: test
  image: ubuntu:latest
  before_script:
    - apt-get update && apt-get install -y git curl
    - git clone https://github.com/Gentleman-Programming/gentleman-guardian-angel.git /opt/gga
    - export PATH="/opt/gga/bin:$PATH"
    # Install your provider CLI here
  script:
    - git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA | xargs git add
    - gga run
  only:
    - merge_requests

๐Ÿ› Troubleshooting

"Provider not found"

# Check if your provider CLI is installed and in PATH
which claude   # Should show: /usr/local/bin/claude or similar
which gemini
which codex
which ollama

# Test if the provider works
echo "Say hello" | claude --print

"Rules file not found"

The tool requires a rules file to know what to check:

# Create your rules file
touch AGENTS.md

# Add your coding standards
echo "# My Coding Standards" > AGENTS.md
echo "- No console.log in production" >> AGENTS.md

"Ambiguous response" in Strict Mode

The AI must respond with STATUS: PASSED or STATUS: FAILED as the first line. If it doesn't:

  1. Try Claude (most reliable at following instructions)
  2. Check your rules file isn't confusing the AI
  3. Temporarily disable strict mode: STRICT_MODE="false"

Slow reviews on large files

The tool sends full file contents. For better performance:

# Add large/generated files to exclude
EXCLUDE_PATTERNS="*.min.js,*.bundle.js,dist/*,build/*,*.generated.ts"

๐Ÿงช Development

Project Structure

gentleman-guardian-angel/
โ”œโ”€โ”€ bin/
โ”‚   โ””โ”€โ”€ gga                    # Main CLI script
โ”œโ”€โ”€ lib/
โ”‚   โ”œโ”€โ”€ providers.sh           # AI provider implementations
โ”‚   โ””โ”€โ”€ cache.sh               # Smart caching logic
โ”œโ”€โ”€ spec/                      # ShellSpec test suite
โ”‚   โ”œโ”€โ”€ spec_helper.sh         # Test setup and helpers
โ”‚   โ”œโ”€โ”€ unit/
โ”‚   โ”‚   โ”œโ”€โ”€ cache_spec.sh      # Cache unit tests (27 tests)
โ”‚   โ”‚   โ””โ”€โ”€ providers_spec.sh  # Provider unit tests (13 tests)
โ”‚   โ””โ”€โ”€ integration/
โ”‚       โ””โ”€โ”€ commands_spec.sh   # CLI integration tests (28 tests)
โ”œโ”€โ”€ Makefile                   # Development commands
โ”œโ”€โ”€ .shellspec                 # Test runner config
โ”œโ”€โ”€ install.sh                 # Manual installer
โ”œโ”€โ”€ uninstall.sh               # Uninstaller
โ””โ”€โ”€ README.md

Running Tests

GGA uses ShellSpec for testing - a BDD-style testing framework for shell scripts.

# Install dependencies (once)
brew install shellspec shellcheck

# Run all tests (68 total)
make test

# Run specific test suites
make test-unit        # Unit tests only (40 tests)
make test-integration # Integration tests only (28 tests)

# Lint shell scripts with shellcheck
make lint

# Run all checks before commit (lint + tests)
make check

Test Coverage

Module Tests Description
cache.sh 27 Hash functions, cache validation, file caching
providers.sh 13 Provider parsing, validation, info display
CLI commands 28 init, install, uninstall, run, config, cache
Total 68 Full coverage of core functionality

Adding New Tests

# Create a new spec file
touch spec/unit/my_feature_spec.sh

# Run only your new tests
shellspec spec/unit/my_feature_spec.sh

๐Ÿ“‹ Changelog

v2.2.0 (Latest)

  • โœ… Added comprehensive test suite with 68 tests
  • โœ… Unit tests for cache.sh and providers.sh
  • โœ… Integration tests for all CLI commands
  • โœ… Added Makefile with test, lint, check targets
  • โœ… Fixed shellcheck warnings

v2.1.0

  • โœ… Smart caching system - skip unchanged files
  • โœ… Auto-invalidation when AGENTS.md or .gga changes
  • โœ… Cache commands: status, clear, clear-all
  • โœ… --no-cache flag to bypass caching

v2.0.0

  • โœ… Renamed to Gentleman Guardian Angel (gga)
  • โœ… Auto-migration from legacy ai-code-review hooks
  • โœ… Homebrew tap distribution

v1.0.0

  • โœ… Initial release with Claude, Gemini, Codex, Ollama support
  • โœ… File patterns and exclusions
  • โœ… Strict mode for CI/CD

๐Ÿค Contributing

Contributions are welcome! Some ideas:

  • Add more providers (Copilot, Codeium, etc.)
  • Support for .gga.yaml format
  • Caching to avoid re-reviewing unchanged files โœ… Done in v2.1.0
  • Add test suite โœ… Done in v2.2.0
  • GitHub Action version
  • Output formats (JSON, SARIF for IDE integration)
# Fork, clone, and submit PRs!
git clone https://github.com/Gentleman-Programming/gentleman-guardian-angel.git
cd gentleman-guardian-angel

# Run tests before submitting
make check

๐Ÿ“„ License

MIT ยฉ 2024


Built with ๐Ÿง‰ by developers who got tired of repeating the same code review comments