vibecop 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +68 -303
  2. package/dist/cli.js +24752 -8398
  3. package/package.json +7 -2
package/README.md CHANGED
@@ -6,357 +6,122 @@
6
6
  [![CI](https://github.com/bhvbhushan/vibecop/actions/workflows/ci.yml/badge.svg)](https://github.com/bhvbhushan/vibecop/actions/workflows/ci.yml)
7
7
  [![Playground](https://img.shields.io/badge/Try-Playground-orange)](https://vibecop-pg.bhvbhushan7.com/)
8
8
 
9
- AI code quality toolkit — deterministic linter for the AI coding era. 28 detectors catch the bugs AI agents introduce: god functions, N+1 queries, unsafe shell exec, unpinned LLM models, and more. Runs automatically inside Claude Code, Cursor, Codex, Aider, and 3 other AI tools via `vibecop init`.
9
+ AI code quality toolkit — deterministic linter for the AI coding era. 35 detectors catch the bugs AI agents introduce: god functions, N+1 queries, unsafe shell exec, unpinned LLM models, and more. Runs automatically inside Claude Code, Cursor, Codex, Aider, and 7 other AI tools. Also available as an MCP server.
10
10
 
11
11
  Built on [ast-grep](https://ast-grep.github.io/) for fast, tree-sitter-based AST analysis. No LLM required — every finding is deterministic and reproducible.
12
12
 
13
- ## Try it Online
14
-
15
- **[Playground](https://vibecop-pg.bhvbhushan7.com/)** — paste code and scan instantly in your browser.
13
+ **[Documentation](https://bhvbhushan.github.io/vibecop/)** | **[Playground](https://vibecop-pg.bhvbhushan7.com/)**
16
14
 
17
15
  ## Install
18
16
 
19
17
  ```bash
20
- # npm
21
- npm install -g vibecop
22
-
23
- # bun (recommended)
24
- bun add -g vibecop
18
+ npm install -g vibecop # or: bun add -g vibecop
25
19
  ```
26
20
 
27
- Requires Node.js >= 20 or Bun >= 1.0.
28
-
29
21
  ## Quick Start
30
22
 
31
23
  ```bash
32
- # Scan current directory
33
- vibecop scan .
34
-
35
- # Scan specific directory with JSON output
36
- vibecop scan src/ --format json
37
-
38
- # Check what detectors are available
39
- vibecop check
40
-
41
- # CI mode — exit code 1 if errors found
42
- vibecop scan . --format text
43
-
44
- # Scan with custom config
45
- vibecop scan . --config .vibecop.yml
24
+ vibecop scan . # Scan current directory
25
+ vibecop scan src/ --format json # JSON output
26
+ vibecop scan . --diff HEAD # Only changed files
27
+ vibecop init # Auto-setup agent integration
28
+ vibecop serve # Start MCP server
46
29
  ```
47
30
 
48
31
  ## Agent Integration
49
32
 
50
- vibecop runs automatically inside your AI coding agent. Every time the agent edits a file, vibecop scans the change and blocks on findings — the agent reads the output and fixes the issue before proceeding.
51
-
52
- ### Auto-setup (recommended)
33
+ vibecop runs inside your AI coding agent. Every edit triggers a scan — the agent reads findings and self-corrects.
53
34
 
54
35
  ```bash
55
- npx vibecop init
36
+ npx vibecop init # Auto-detects tools, generates configs
56
37
  ```
57
38
 
58
- Detects which tools you have installed and generates the right config files:
39
+ | Tool | Integration |
40
+ |------|-------------|
41
+ | **Claude Code** | PostToolUse hook |
42
+ | **Cursor** | afterFileEdit hook + rules |
43
+ | **Codex CLI** | PostToolUse hook |
44
+ | **Aider** | Native `--lint-cmd` |
45
+ | **GitHub Copilot** | Custom instructions |
46
+ | **Windsurf** | Rules file |
47
+ | **Cline/Roo Code** | `.clinerules` |
48
+ | **Continue.dev / Amazon Q / Zed** | MCP server (`vibecop serve`) |
59
49
 
60
50
  ```
61
- vibecop agent integration setup
62
-
63
- Detected tools:
64
- ✓ Claude Code (.claude/ directory found)
65
- ✓ Cursor (.cursor/ directory found)
66
- ✓ Aider (aider installed)
67
- ✗ Codex CLI (not found)
68
-
69
- Generated:
70
- .claude/settings.json — PostToolUse hook (blocks on findings)
71
- .cursor/hooks.json — afterFileEdit hook
72
- .cursor/rules/vibecop.md — always-on lint rule
73
- .aider.conf.yml — lint-cmd per language
74
-
75
- Done! vibecop will now run automatically in your agent workflow.
51
+ Agent writes code → vibecop hook fires Findings? Agent fixes → Clean? Continue.
76
52
  ```
77
53
 
78
- ### Supported tools
79
-
80
- | Tool | Integration | How it works |
81
- |------|-------------|--------------|
82
- | **Claude Code** | PostToolUse hook | Runs after every Edit/Write, exit 1 blocks and forces fix |
83
- | **Cursor** | afterFileEdit hook + rules | Hook runs scan, rules file tells agent to fix findings |
84
- | **Codex CLI** | PostToolUse hook | Same pattern as Claude Code |
85
- | **Aider** | Native `--lint-cmd` | Built-in lint integration, runs after every edit |
86
- | **GitHub Copilot** | Custom instructions | Instructions file tells agent to run vibecop |
87
- | **Windsurf** | Rules file | `trigger: always_on` rule |
88
- | **Cline/Roo Code** | `.clinerules` | Rules file tells agent to run vibecop |
89
-
90
- ### Manual setup (Claude Code example)
91
-
92
- Add to `.claude/settings.json`:
54
+ ## MCP Server
93
55
 
94
56
  ```json
95
57
  {
96
- "hooks": {
97
- "PostToolUse": [{
98
- "matcher": "Edit|Write|MultiEdit",
99
- "hooks": [{
100
- "type": "command",
101
- "command": "npx vibecop scan --diff HEAD --format agent"
102
- }]
103
- }]
58
+ "mcpServers": {
59
+ "vibecop": {
60
+ "command": "npx",
61
+ "args": ["vibecop", "serve"]
62
+ }
104
63
  }
105
64
  }
106
65
  ```
107
66
 
108
- ### How the loop works
109
-
110
- ```
111
- Agent writes code
112
- → vibecop hook fires automatically
113
- → Findings? Exit 1 → agent reads output, fixes code
114
- → No findings? Exit 0 → agent continues
115
- ```
116
-
117
- The `--format agent` output is token-efficient (one finding per line, ~30 tokens each):
118
-
119
- ```
120
- src/api.ts:42:1 error unsafe-shell-exec: execSync() with template literal. Use execFile() with argument array instead.
121
- src/llm.ts:18:5 warning llm-unpinned-model: Unpinned model alias "gpt-4o". Pin to a dated version like "gpt-4o-2024-08-06".
122
- ```
123
-
124
- See [docs/agent-integration.md](docs/agent-integration.md) for full setup instructions and troubleshooting.
67
+ Three tools: `vibecop_scan`, `vibecop_check`, `vibecop_explain`.
125
68
 
126
69
  ## Benchmarks
127
70
 
128
- ### Vibe-coded vs established: finding density comparison
129
-
130
- All numbers below are real — run `vibecop scan` on any of these repos yourself to reproduce. Finding density = findings per 1,000 lines of code.
131
-
132
- **Established projects (professionally maintained):**
133
-
134
- | Project | Stars | Files | LOC | Findings | Density |
135
- |---------|:-----:|:-----:|----:|:--------:|--------:|
136
- | [**fastify**](https://github.com/fastify/fastify) | 65K | 275 | 74,428 | 124 | 1.7/kLOC |
137
- | [**date-fns**](https://github.com/date-fns/date-fns) | 35K | 1,543 | 99,859 | 308 | 3.1/kLOC |
138
- | [**TanStack/query**](https://github.com/TanStack/query) | 43K | 997 | 148,492 | 652 | 4.4/kLOC |
139
- | [**express**](https://github.com/expressjs/express) | 66K | 141 | 21,346 | 123 | 5.8/kLOC |
140
- | [**zod**](https://github.com/colinhacks/zod) | 35K | 356 | 70,886 | 964 | 13.6/kLOC |
141
-
142
- **Vibe-coded projects (AI-generated/assisted):**
143
-
144
- | Project | Stars | Files | LOC | Findings | Density |
145
- |---------|:-----:|:-----:|----:|:--------:|--------:|
146
- | [**dyad**](https://github.com/dyad-sh/dyad) | 20K | 956 | 147,284 | 1,179 | 8.0/kLOC |
147
- | [**bolt.diy**](https://github.com/stackblitz-labs/bolt.diy) | 19.2K | 392 | 71,639 | 977 | 13.6/kLOC |
148
- | [**code-review-graph**](https://github.com/tirth8205/code-review-graph) | 3.9K | 95 | 27,119 | 361 | 13.3/kLOC |
149
- | [**context7**](https://github.com/upstash/context7) | 51.3K | 71 | 9,201 | 129 | 14.0/kLOC |
150
- | [**vibe-check-mcp**](https://github.com/PV-Bhat/vibe-check-mcp-server) | 480 | 55 | 5,964 | 119 | 20.0/kLOC |
151
- | [**magic-mcp**](https://github.com/21st-dev/magic-mcp) | 4.6K | 14 | 1,096 | 28 | 25.5/kLOC |
152
- | [**browser-tools-mcp**](https://github.com/AgentDeskAI/browser-tools-mcp) | 7.2K | 12 | 8,346 | 414 | 49.6/kLOC |
153
-
154
- **Median density: established 4.4/kLOC vs vibe-coded 14.0/kLOC (3.2x higher).** Vibe-coded projects consistently trigger more findings per line of code. The v0.2 detectors found **157 additional issues** across vibe-coded repos that v0.1 missed: 63 unsafe shell executions, 53 unpinned LLM models, 39 missing system messages.
155
-
156
- > **Note:** Some established repos show higher-than-expected density for valid reasons — zod uses `any` deliberately for type gymnastics (634 of its 964 findings), date-fns has extensive JSDoc (218 comment-ratio findings). vibecop detects patterns, not intent. Use `.vibecop.yml` to tune or disable detectors for your codebase.
71
+ All numbers are real run `vibecop scan` on any repo to reproduce.
157
72
 
158
- ### Example Output
73
+ **Established projects:**
159
74
 
160
- ```
161
- src/services/user.service.ts
162
- 45:1 error Function 'processUserData' is too complex (232 lines, cyclomatic complexity 41, 3 params) god-function
163
- 89:5 warning Database or API call inside a loop — potential N+1 query n-plus-one-query
164
- 145:5 warning Database mutation result is not checked — errors will be silently ignored unchecked-db-result
165
-
166
- src/components/PaymentModal.tsx
167
- 1:1 warning Component has too many hooks (8 useState, 3 useEffect, 593 lines) god-component
168
- 201:9 warning dangerouslySetInnerHTML can lead to XSS attacks if the content is not sanitized dangerous-inner-html
75
+ | Project | Density |
76
+ |---------|--------:|
77
+ | [fastify](https://github.com/fastify/fastify) (65K stars) | 1.7/kLOC |
78
+ | [date-fns](https://github.com/date-fns/date-fns) (35K stars) | 3.1/kLOC |
79
+ | [TanStack/query](https://github.com/TanStack/query) (43K stars) | 4.4/kLOC |
80
+ | [express](https://github.com/expressjs/express) (66K stars) | 5.8/kLOC |
169
81
 
170
- src/config/auth.ts
171
- 12:5 error Placeholder placeholder domain found: "yourdomain.com" placeholder-in-production
172
- 18:5 error Auth token stored in localStorage — vulnerable to XSS token-in-localstorage
82
+ **Vibe-coded projects:**
173
83
 
174
- src/utils/api.ts
175
- 34:12 warning Double type assertion (as unknown as X) bypasses TypeScript's type safety double-type-assertion
176
- 67:1 info TODO comment in production code (security-related) todo-in-production
177
-
178
- 9 problems (3 errors, 5 warnings, 1 info)
179
- ```
84
+ | Project | Density |
85
+ |---------|--------:|
86
+ | [dyad](https://github.com/dyad-sh/dyad) (20K stars) | 8.0/kLOC |
87
+ | [bolt.diy](https://github.com/stackblitz-labs/bolt.diy) (19K stars) | 13.6/kLOC |
88
+ | [context7](https://github.com/upstash/context7) (51K stars) | 14.0/kLOC |
89
+ | [browser-tools-mcp](https://github.com/AgentDeskAI/browser-tools-mcp) (7K stars) | 49.6/kLOC |
180
90
 
181
- ## Detectors (28 total)
182
-
183
- ### Quality (16 detectors)
184
-
185
- | ID | Detector | Description | Severity |
186
- |----|----------|-------------|----------|
187
- | `god-function` | God Function | Functions exceeding line, complexity, or parameter thresholds | error/warning |
188
- | `god-component` | God Component | React components with too many hooks, lines, or imports | warning |
189
- | `n-plus-one-query` | N+1 Query | DB/API calls inside loops or `.map(async ...)` callbacks | warning |
190
- | `unbounded-query` | Unbounded Query | `findMany`/`findAll` without a `take`/`limit` clause | info |
191
- | `debug-console-in-prod` | Debug Console in Prod | `console.log`/`console.debug` left in production code | warning |
192
- | `dead-code-path` | Dead Code Path | Identical if/else branches, unreachable code after return/throw | warning |
193
- | `double-type-assertion` | Double Type Assertion | `as unknown as X` patterns that bypass TypeScript type safety | warning |
194
- | `excessive-any` | Excessive Any | Files with 4+ `any` type annotations | warning |
195
- | `todo-in-production` | TODO in Production | TODO/FIXME/HACK comments, escalated if security-related | info/warning |
196
- | `empty-error-handler` | Empty Error Handler | Catch/except blocks that silently swallow errors | warning |
197
- | `excessive-comment-ratio` | Excessive Comment Ratio | Files with >50% comment lines | info |
198
- | `over-defensive-coding` | Over-Defensive Coding | Redundant null checks on values that can't be null | info |
199
- | `llm-call-no-timeout` | LLM Call No Timeout | `new OpenAI()`/`new Anthropic()` without timeout, `.create()` without max_tokens | warning |
200
- | `llm-unpinned-model` | LLM Unpinned Model | Moving model aliases like `"gpt-4o"` that silently change behavior | warning |
201
- | `llm-temperature-not-set` | LLM Temperature Not Set | LLM `.create()` calls without explicit `temperature` parameter | info |
202
- | `llm-no-system-message` | LLM No System Message | Chat API calls without a `role: "system"` message | info |
203
-
204
- ### Security (7 detectors)
205
-
206
- | ID | Detector | Description | Severity |
207
- |----|----------|-------------|----------|
208
- | `sql-injection` | SQL Injection | Template literals or string concatenation in SQL query methods | error |
209
- | `dangerous-inner-html` | Dangerous innerHTML | `dangerouslySetInnerHTML` usage without sanitization | warning |
210
- | `token-in-localstorage` | Token in localStorage | Auth/JWT tokens stored in XSS-accessible storage | error |
211
- | `placeholder-in-production` | Placeholder in Production | `yourdomain.com`, `changeme`, `xxx` left in config | error |
212
- | `insecure-defaults` | Insecure Defaults | `eval()`, `rejectUnauthorized: false`, hardcoded credentials | error |
213
- | `unsafe-shell-exec` | Unsafe Shell Exec | `exec()`/`execSync()` with dynamic args, `subprocess` with `shell=True` | error |
214
- | `dynamic-code-exec` | Dynamic Code Exec | `eval(variable)`, `new Function(variable)` with non-literal arguments | error |
215
-
216
- ### Correctness (4 detectors)
217
-
218
- | ID | Detector | Description | Severity |
219
- |----|----------|-------------|----------|
220
- | `unchecked-db-result` | Unchecked DB Result | Fire-and-forget database mutations (insert/update/delete) | warning |
221
- | `undeclared-import` | Undeclared Import | Imports not declared in package.json/requirements.txt | error |
222
- | `mixed-concerns` | Mixed Concerns | Files importing both UI frameworks and database/server libraries | warning |
223
- | `hallucinated-package` | Hallucinated Package | Dependencies not in top-5K npm allowlist (potential AI hallucination) | info |
224
-
225
- ### Testing (2 detectors)
226
-
227
- | ID | Detector | Description | Severity |
228
- |----|----------|-------------|----------|
229
- | `trivial-assertion` | Trivial Assertion | `expect(true).toBe(true)` and similar no-op tests | info |
230
- | `over-mocking` | Over-Mocking | Test files with excessive mock/spy usage | info |
91
+ **Median: established 4.4/kLOC vs vibe-coded 14.0/kLOC (3.2x higher).**
231
92
 
232
93
  ## GitHub Action
233
94
 
234
- Add vibecop as a PR gate that posts inline review comments on changed lines:
235
-
236
95
  ```yaml
237
- # .github/workflows/vibecop.yml
238
- name: vibecop
239
- on: [pull_request]
240
-
241
- jobs:
242
- scan:
243
- runs-on: ubuntu-latest
244
- steps:
245
- - uses: actions/checkout@v4
246
- - uses: bhvbhushan/vibecop@main
247
- with:
248
- on-failure: comment-only # or: request-changes, label, auto-close
249
- severity-threshold: warning
250
- max-findings: 50
96
+ - uses: bhvbhushan/vibecop@main
97
+ with:
98
+ on-failure: comment-only
99
+ severity-threshold: warning
251
100
  ```
252
101
 
253
- ### Action Inputs
254
-
255
- | Input | Description | Default |
256
- |-------|-------------|---------|
257
- | `github-token` | GitHub token for API access | `${{ github.token }}` |
258
- | `config` | Path to `.vibecop.yml` config file | `.vibecop.yml` |
259
- | `on-failure` | Action on findings: `comment-only`, `request-changes`, `label`, `auto-close` | `comment-only` |
260
- | `label` | Label to apply when `on-failure` is `label` | `vibecop:needs-review` |
261
- | `max-findings` | Maximum findings to report (0 = unlimited) | `50` |
262
- | `severity-threshold` | Minimum severity for inline comments (`error`, `warning`, `info`) | `warning` |
263
- | `working-directory` | Directory to scan (relative to repo root) | `.` |
264
-
265
- ### Action Outputs
266
-
267
- | Output | Description |
268
- |--------|-------------|
269
- | `findings-count` | Total number of findings |
270
- | `errors-count` | Number of error-severity findings |
271
- | `warnings-count` | Number of warning-severity findings |
272
- | `has-findings` | Whether any findings were detected (`true`/`false`) |
273
- | `scan-time-ms` | Scan duration in milliseconds |
274
-
275
- ## Configuration
276
-
277
- Create `.vibecop.yml` in your project root:
278
-
279
- ```yaml
280
- rules:
281
- god-function:
282
- severity: warning
283
- debug-console-in-prod:
284
- severity: "off" # disable a detector
285
- excessive-any:
286
- severity: warning
287
-
288
- ignore:
289
- - "**/dist/**"
290
- - "**/vendor/**"
291
- - "**/generated/**"
292
-
293
- pr-gate:
294
- on-failure: request-changes
295
- severity-threshold: warning
296
- max-findings: 50
297
- label: "vibecop:needs-review"
298
- ```
299
-
300
- ## CLI Options
301
-
302
- | Flag | Description | Default |
303
- |------|-------------|---------|
304
- | `--format` | Output format: `text`, `json`, `html`, `sarif`, `github`, `agent` | `text` |
305
- | `--config` | Path to config file | `.vibecop.yml` |
306
- | `--no-config` | Ignore config file | |
307
- | `--max-findings` | Maximum findings to report | `100` |
308
- | `--output` | Write report to file | |
102
+ ## Detectors (35)
309
103
 
310
- ## Languages
104
+ 4 categories: **Quality** (16), **Security** (7), **Correctness** (4), **Testing** (8).
311
105
 
312
- | Language | Extensions | Detectors |
313
- |----------|-----------|-----------|
314
- | TypeScript | `.ts`, `.tsx` | All 28 |
315
- | JavaScript | `.js`, `.jsx`, `.mjs`, `.cjs` | 24 (excludes TS-specific) |
316
- | Python | `.py` | 14 (correctness, quality, security) |
106
+ Catches: god functions, N+1 queries, unsafe shell exec, SQL injection, hardcoded secrets, trivial assertions, empty tests, unpinned LLM models, hallucinated packages, and more.
317
107
 
318
- ## Architecture
319
-
320
- ```
321
- vibecop CLI (Commander)
322
- +-- Scan Engine -- discovers files, loads AST, runs detectors, dedup by priority
323
- +-- Init Wizard -- auto-detects AI tools, generates hook/rule configs
324
- +-- Config Loader (Zod) -- validates .vibecop.yml, merges defaults, per-rule config
325
- +-- Detectors (28) -- AST pattern matching via ast-grep (@ast-grep/napi)
326
- +-- Formatters (6) -- text, json, html, sarif, github, agent output
327
- +-- Project Analyzer -- parses package.json, requirements.txt, lockfiles
328
- +-- GitHub Action -- diff parser, finding filter, PR review poster
329
- ```
330
-
331
- ## Versioning
332
-
333
- vibecop follows [Semantic Versioning](https://semver.org/):
334
-
335
- - **0.x.y** ... pre-1.0, the API may change between minor versions
336
- - **PATCH** (0.x.Y) ... bug fixes, new detectors, doc updates
337
- - **MINOR** (0.X.0) ... new detector categories, output formats, config options
338
- - **MAJOR** (X.0.0) ... breaking CLI changes, removed detectors, config format changes
108
+ [Full detector reference →](https://bhvbhushan.github.io/vibecop/detectors/overview/)
339
109
 
340
110
  ## Roadmap
341
111
 
342
- - [x] **Phase 1**: Core scanner with 7 detectors, 5 output formats, `.vibecop.yml` config
343
- - [x] **Phase 2**: PR Gate GitHub Action, 15 new detectors (7 → 22), real-world validation
344
- - [x] **Phase 2.5**: Agent integration (7 tools), 6 LLM/agent detectors (22 → 28), `vibecop init`, `--format agent`
345
- - [ ] **Phase 3**: MCP server, VS Code extension, cross-file analysis
346
- - [ ] **Phase 4**: LLM-powered deep review mode (separation of concerns, semantic duplication)
347
-
348
- ## Contributing
349
-
350
- See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup, code standards, and how to add new detectors.
351
-
352
- ## Security
353
-
354
- See [SECURITY.md](SECURITY.md) for reporting vulnerabilities.
355
-
356
- ## Code of Conduct
357
-
358
- See [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md).
359
-
360
- ## License
361
-
362
- [MIT](LICENSE)
112
+ - [x] **Phase 1**: Core scanner 7 detectors, 5 output formats
113
+ - [x] **Phase 2**: PR Gate GitHub Action, 15 new detectors
114
+ - [x] **Phase 2.5**: Agent integration (7 tools), 6 LLM/agent detectors, `vibecop init`
115
+ - [x] **Phase 3**: Test quality detectors, custom YAML rules (28 → 35)
116
+ - [x] **Phase 3.5**: MCP server with scan/check/explain tools
117
+ - [ ] **Phase 4**: Context optimization (Read tool interception, AST skeleton caching)
118
+ - [ ] **Phase 5**: VS Code extension, cross-file analysis
119
+
120
+ ## Links
121
+
122
+ - **[Documentation](https://bhvbhushan.github.io/vibecop/)**
123
+ - **[Playground](https://vibecop-pg.bhvbhushan7.com/)**
124
+ - [Contributing](CONTRIBUTING.md)
125
+ - [Security](SECURITY.md)
126
+ - [Changelog](CHANGELOG.md)
127
+ - [License](LICENSE) (MIT)