Skip to content

Commit 89d664f

Browse files
Vapi Taskerclaude
andcommitted
feat: implement @vapi/bulletproof pre-push guardian package
This implements the core BULLETPROOF package that uses Claude to run checks and auto-fix issues before pushing code. Features: - Claude Agent SDK integration for automated fixing - Intelligent diff analysis to determine which checks to run - TypeScript type checking - Test execution with coverage - Git operations (merge, commit, push) - Rich terminal UI with gradients, spinners, and ASCII art - CLI with commander.js - Configurable thresholds and commands Resolves: VAP-11522 Co-Authored-By: Claude <noreply@anthropic.com>
0 parents  commit 89d664f

26 files changed

Lines changed: 8607 additions & 0 deletions

.eslintrc.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"root": true,
3+
"env": {
4+
"node": true,
5+
"es2022": true
6+
},
7+
"parser": "@typescript-eslint/parser",
8+
"parserOptions": {
9+
"ecmaVersion": "latest",
10+
"sourceType": "module"
11+
},
12+
"plugins": ["@typescript-eslint"],
13+
"extends": [
14+
"eslint:recommended"
15+
],
16+
"rules": {
17+
"no-unused-vars": "off",
18+
"@typescript-eslint/no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
19+
"no-undef": "off"
20+
},
21+
"ignorePatterns": ["dist/", "node_modules/"]
22+
}

.gitignore

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build output
5+
dist/
6+
7+
# IDE
8+
.idea/
9+
.vscode/
10+
*.swp
11+
*.swo
12+
13+
# OS
14+
.DS_Store
15+
Thumbs.db
16+
17+
# Logs
18+
*.log
19+
npm-debug.log*
20+
yarn-debug.log*
21+
yarn-error.log*
22+
23+
# Coverage
24+
coverage/
25+
26+
# Environment
27+
.env
28+
.env.local
29+
.env.*.local
30+
31+
# Test artifacts
32+
*.tgz

README.md

Lines changed: 333 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,333 @@
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.

bin/bulletproof.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#!/usr/bin/env node
2+
import '../dist/cli/index.js'

0 commit comments

Comments
 (0)