|
| 1 | +# @vapi/bulletproof |
| 2 | + |
| 3 | +``` |
| 4 | +██████╗ ██╗ ██╗██╗ ██╗ ███████╗████████╗██████╗ ██████╗ ██████╗ ██████╗ ███████╗ |
| 5 | +██╔══██╗██║ ██║██║ ██║ ██╔════╝╚══██╔══╝██╔══██╗██╔══██╗██╔═══██╗██╔═══██╗██╔════╝ |
| 6 | +██████╔╝██║ ██║██║ ██║ █████╗ ██║ ██████╔╝██████╔╝██║ ██║██║ ██║█████╗ |
| 7 | +██╔══██╗██║ ██║██║ ██║ ██╔══╝ ██║ ██╔═══╝ ██╔══██╗██║ ██║██║ ██║██╔══╝ |
| 8 | +██████╔╝╚██████╔╝███████╗███████╗███████╗ ██║ ██║ ██║ ██║╚██████╔╝╚██████╔╝██║ |
| 9 | +╚═════╝ ╚═════╝ ╚══════╝╚══════╝╚══════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═════╝ ╚═╝ |
| 10 | +``` |
| 11 | + |
| 12 | +**Pre-push guardian that uses Claude to run checks and auto-fix issues.** |
| 13 | + |
| 14 | +BULLETPROOF is an AI-powered pre-push guardian that uses Claude (via the Claude Agent SDK) to: |
| 15 | + |
| 16 | +- Run TypeScript type checking |
| 17 | +- Execute test suites |
| 18 | +- Verify coverage thresholds |
| 19 | +- Check code against project conventions |
| 20 | +- **Automatically fix issues** it finds |
| 21 | +- Commit fixes and push to remote |
| 22 | + |
| 23 | +## Features |
| 24 | + |
| 25 | +- **Intelligent Diff Analysis**: Analyzes git diff to determine which checks to run |
| 26 | +- **Smart Test Selection**: Runs only related tests for small changes |
| 27 | +- **Auto-Fix**: Claude automatically fixes type errors, test failures, and convention violations |
| 28 | +- **Beautiful Terminal UI**: Animated logos, gradient colors, progress indicators |
| 29 | +- **Agent Mode**: Clean output for CI/CD and non-interactive environments |
| 30 | +- **Configurable**: Customize thresholds, commands, and behavior |
| 31 | + |
| 32 | +## Installation |
| 33 | + |
| 34 | +```bash |
| 35 | +# Using npm |
| 36 | +npm install @vapi/bulletproof |
| 37 | + |
| 38 | +# Using yarn |
| 39 | +yarn add @vapi/bulletproof |
| 40 | + |
| 41 | +# Using pnpm |
| 42 | +pnpm add @vapi/bulletproof |
| 43 | +``` |
| 44 | + |
| 45 | +## Quick Start |
| 46 | + |
| 47 | +### CLI Usage |
| 48 | + |
| 49 | +```bash |
| 50 | +# Run checks and push (default behavior) |
| 51 | +npx bulletproof |
| 52 | + |
| 53 | +# Run checks without pushing |
| 54 | +npx bulletproof --no-push |
| 55 | + |
| 56 | +# Run in git hook mode (minimal output) |
| 57 | +npx bulletproof --hook |
| 58 | + |
| 59 | +# Run in agent/CI mode (no animations) |
| 60 | +npx bulletproof --agent |
| 61 | + |
| 62 | +# Show verbose output |
| 63 | +npx bulletproof --verbose |
| 64 | +``` |
| 65 | + |
| 66 | +### Initialize Configuration |
| 67 | + |
| 68 | +```bash |
| 69 | +npx bulletproof init |
| 70 | +``` |
| 71 | + |
| 72 | +This creates a `bulletproof.config.json` file with default settings. |
| 73 | + |
| 74 | +### Programmatic Usage |
| 75 | + |
| 76 | +```typescript |
| 77 | +import { runGuardian, GuardianRunner } from '@vapi/bulletproof' |
| 78 | + |
| 79 | +// Simple usage |
| 80 | +const result = await runGuardian({ |
| 81 | + skipPush: true, |
| 82 | + verbose: true, |
| 83 | +}) |
| 84 | + |
| 85 | +if (result.success) { |
| 86 | + console.log('All checks passed!') |
| 87 | +} else { |
| 88 | + console.log('Checks failed:', result.error) |
| 89 | +} |
| 90 | + |
| 91 | +// Advanced usage |
| 92 | +const guardian = new GuardianRunner({ |
| 93 | + hookMode: true, |
| 94 | + cwd: '/path/to/project', |
| 95 | +}) |
| 96 | + |
| 97 | +const result = await guardian.run() |
| 98 | +console.log('Elapsed:', result.elapsed) |
| 99 | +console.log('Analysis:', result.analysis.reason) |
| 100 | +``` |
| 101 | + |
| 102 | +## Configuration |
| 103 | + |
| 104 | +BULLETPROOF looks for configuration in the following locations (in order): |
| 105 | + |
| 106 | +1. `bulletproof.config.json` |
| 107 | +2. `bulletproof.config.js` |
| 108 | +3. `.bulletproofrc` |
| 109 | +4. `.bulletproofrc.json` |
| 110 | +5. `bulletproof` key in `package.json` |
| 111 | + |
| 112 | +### Configuration Options |
| 113 | + |
| 114 | +```json |
| 115 | +{ |
| 116 | + "model": "claude-opus-4-5-20251101", |
| 117 | + "maxTurns": 50, |
| 118 | + "coverageThresholds": { |
| 119 | + "lines": 90, |
| 120 | + "statements": 90, |
| 121 | + "functions": 78, |
| 122 | + "branches": 80 |
| 123 | + }, |
| 124 | + "coverageScope": { |
| 125 | + "include": ["src/**/*.ts", "src/**/*.tsx"], |
| 126 | + "exclude": [ |
| 127 | + "src/test/**", |
| 128 | + "**/*.test.ts", |
| 129 | + "**/*.spec.ts", |
| 130 | + "**/types/**", |
| 131 | + "**/*.d.ts" |
| 132 | + ] |
| 133 | + }, |
| 134 | + "checks": { |
| 135 | + "rules": true, |
| 136 | + "typecheck": true, |
| 137 | + "tests": true, |
| 138 | + "coverage": true |
| 139 | + }, |
| 140 | + "commands": { |
| 141 | + "typecheck": "npm run typecheck", |
| 142 | + "test": "npm run test", |
| 143 | + "testCoverage": "npm run test:coverage:ci", |
| 144 | + "testRelated": "npm run test:related", |
| 145 | + "testCoverageRelated": "npm run test:coverage:related" |
| 146 | + }, |
| 147 | + "rulesFile": ".cursorrules", |
| 148 | + "systemPrompt": "Additional system prompt instructions...", |
| 149 | + "additionalInstructions": "Additional task instructions..." |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +### Configuration Reference |
| 154 | + |
| 155 | +| Option | Type | Default | Description | |
| 156 | +|--------|------|---------|-------------| |
| 157 | +| `model` | string | `claude-opus-4-5-20251101` | Claude model to use | |
| 158 | +| `maxTurns` | number | `50` | Maximum Claude agent turns | |
| 159 | +| `coverageThresholds` | object | See below | Coverage percentage thresholds | |
| 160 | +| `coverageScope` | object | See below | Patterns for coverage scope | |
| 161 | +| `checks` | object | All true | Which checks to run | |
| 162 | +| `commands` | object | See below | NPM scripts for each check | |
| 163 | +| `rulesFile` | string | `.cursorrules` | Path to project rules file | |
| 164 | +| `systemPrompt` | string | - | Additional system prompt | |
| 165 | +| `additionalInstructions` | string | - | Additional task instructions | |
| 166 | + |
| 167 | +## Git Hook Integration |
| 168 | + |
| 169 | +### Using Husky |
| 170 | + |
| 171 | +```bash |
| 172 | +# Install husky |
| 173 | +npm install -D husky |
| 174 | +npx husky init |
| 175 | + |
| 176 | +# Add pre-push hook |
| 177 | +echo 'npx bulletproof --hook' > .husky/pre-push |
| 178 | +``` |
| 179 | + |
| 180 | +### Manual Git Hook |
| 181 | + |
| 182 | +Create `.git/hooks/pre-push`: |
| 183 | + |
| 184 | +```bash |
| 185 | +#!/bin/sh |
| 186 | +npx bulletproof --hook |
| 187 | +``` |
| 188 | + |
| 189 | +Make it executable: |
| 190 | + |
| 191 | +```bash |
| 192 | +chmod +x .git/hooks/pre-push |
| 193 | +``` |
| 194 | + |
| 195 | +## CI/CD Integration |
| 196 | + |
| 197 | +BULLETPROOF automatically detects CI environments and runs in agent mode. |
| 198 | + |
| 199 | +### GitHub Actions |
| 200 | + |
| 201 | +```yaml |
| 202 | +name: BULLETPROOF |
| 203 | +on: [push, pull_request] |
| 204 | + |
| 205 | +jobs: |
| 206 | + check: |
| 207 | + runs-on: ubuntu-latest |
| 208 | + steps: |
| 209 | + - uses: actions/checkout@v4 |
| 210 | + - uses: actions/setup-node@v4 |
| 211 | + with: |
| 212 | + node-version: '20' |
| 213 | + - run: npm ci |
| 214 | + - run: npx bulletproof --no-push |
| 215 | + env: |
| 216 | + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} |
| 217 | +``` |
| 218 | +
|
| 219 | +## How It Works |
| 220 | +
|
| 221 | +### 1. Diff Analysis |
| 222 | +
|
| 223 | +BULLETPROOF analyzes your git diff to intelligently select which checks to run: |
| 224 | +
|
| 225 | +- **Docs only**: Skip all checks except rules compliance |
| 226 | +- **Config only**: Skip tests and coverage |
| 227 | +- **Scripts only**: Skip coverage |
| 228 | +- **Small diff**: Run related tests only |
| 229 | +- **Large diff**: Run full test suite |
| 230 | +
|
| 231 | +### 2. Check Execution |
| 232 | +
|
| 233 | +Claude runs the following checks in order: |
| 234 | +
|
| 235 | +1. **Rules Compliance**: Reviews changed files against `.cursorrules` |
| 236 | +2. **TypeScript**: Runs `npm run typecheck` |
| 237 | +3. **Tests**: Runs test suite (full or related) |
| 238 | +4. **Coverage**: Verifies coverage thresholds |
| 239 | + |
| 240 | +### 3. Auto-Fix |
| 241 | + |
| 242 | +When issues are found, Claude: |
| 243 | + |
| 244 | +1. Analyzes the error |
| 245 | +2. Reads relevant files |
| 246 | +3. Makes minimal fixes |
| 247 | +4. Re-runs the check |
| 248 | +5. Iterates until fixed or max turns reached |
| 249 | + |
| 250 | +### 4. Commit & Push |
| 251 | + |
| 252 | +After all checks pass: |
| 253 | + |
| 254 | +1. Commits any auto-fix changes |
| 255 | +2. Pushes to remote (unless `--no-push`) |
| 256 | + |
| 257 | +## API Reference |
| 258 | + |
| 259 | +### `runGuardian(options)` |
| 260 | + |
| 261 | +Main function to run the guardian. |
| 262 | + |
| 263 | +```typescript |
| 264 | +interface GuardianOptions { |
| 265 | + skipPush?: boolean // Skip pushing to remote |
| 266 | + hookMode?: boolean // Mini logo, quick banners |
| 267 | + agentMode?: boolean // Non-interactive mode |
| 268 | + verbose?: boolean // Show detailed output |
| 269 | + cwd?: string // Working directory |
| 270 | +} |
| 271 | +
|
| 272 | +interface GuardianResult { |
| 273 | + success: boolean |
| 274 | + elapsed: string |
| 275 | + analysis: DiffAnalysis |
| 276 | + fixesCommitted: boolean |
| 277 | + pushed: boolean |
| 278 | + error?: string |
| 279 | +} |
| 280 | +``` |
| 281 | + |
| 282 | +### `GuardianRunner` |
| 283 | + |
| 284 | +Class-based API for more control. |
| 285 | + |
| 286 | +```typescript |
| 287 | +const guardian = new GuardianRunner(options) |
| 288 | +const config = guardian.getConfig() |
| 289 | +const result = await guardian.run() |
| 290 | +``` |
| 291 | + |
| 292 | +### `analyzeDiff(config, cwd)` |
| 293 | + |
| 294 | +Analyze git diff and determine which checks to run. |
| 295 | + |
| 296 | +```typescript |
| 297 | +const analysis = analyzeDiff(config, process.cwd()) |
| 298 | +console.log(analysis.reason) |
| 299 | +console.log(analysis.checks) |
| 300 | +console.log(analysis.useRelatedTests) |
| 301 | +``` |
| 302 | + |
| 303 | +### `loadConfig(cwd)` |
| 304 | + |
| 305 | +Load and merge configuration. |
| 306 | + |
| 307 | +```typescript |
| 308 | +const config = loadConfig('/path/to/project') |
| 309 | +console.log(config.model) |
| 310 | +console.log(config.coverageThresholds) |
| 311 | +``` |
| 312 | + |
| 313 | +## Environment Variables |
| 314 | + |
| 315 | +| Variable | Description | |
| 316 | +|----------|-------------| |
| 317 | +| `ANTHROPIC_API_KEY` | API key for Claude (required) | |
| 318 | +| `CI` | Set to `true` for agent mode | |
| 319 | +| `AGENT_MODE` | Set to `true` for agent mode | |
| 320 | + |
| 321 | +## Requirements |
| 322 | + |
| 323 | +- Node.js >= 18.0.0 |
| 324 | +- Git |
| 325 | +- Anthropic API key (for Claude) |
| 326 | + |
| 327 | +## License |
| 328 | + |
| 329 | +MIT |
| 330 | + |
| 331 | +## Contributing |
| 332 | + |
| 333 | +Contributions are welcome! Please read our contributing guidelines before submitting a PR. |
0 commit comments