diffray 0.1.3 → 0.2.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 (32) hide show
  1. package/README.md +866 -250
  2. package/dist/defaults/agents/api-design.md +31 -0
  3. package/dist/defaults/agents/bug-hunter.md +0 -1
  4. package/dist/defaults/agents/consistency-check.md +27 -0
  5. package/dist/defaults/agents/data-privacy.md +30 -0
  6. package/dist/defaults/agents/database.md +30 -0
  7. package/dist/defaults/agents/general.md +0 -1
  8. package/dist/defaults/agents/i18n.md +29 -0
  9. package/dist/defaults/agents/observability.md +30 -0
  10. package/dist/defaults/agents/performance-check.md +0 -1
  11. package/dist/defaults/agents/security-scan.md +0 -1
  12. package/dist/defaults/agents/validation.md +0 -1
  13. package/dist/defaults/prompts/INDEX.md +178 -0
  14. package/dist/defaults/prompts/README.md +173 -0
  15. package/dist/defaults/prompts/SUMMARY.md +276 -0
  16. package/dist/defaults/prompts/USAGE.md +277 -0
  17. package/dist/defaults/prompts/api-design.md +119 -0
  18. package/dist/defaults/prompts/data-privacy.md +144 -0
  19. package/dist/defaults/prompts/database.md +105 -0
  20. package/dist/defaults/prompts/i18n.md +89 -0
  21. package/dist/defaults/prompts/observability.md +142 -0
  22. package/dist/defaults/rules/code-consistency.md +74 -0
  23. package/dist/diffray.cjs +347 -0
  24. package/package.json +29 -13
  25. package/src/defaults/agents/bug-hunter.md +0 -1
  26. package/src/defaults/agents/consistency-check.md +27 -0
  27. package/src/defaults/agents/general.md +0 -1
  28. package/src/defaults/agents/performance-check.md +0 -1
  29. package/src/defaults/agents/security-scan.md +0 -1
  30. package/src/defaults/agents/validation.md +0 -1
  31. package/src/defaults/rules/code-consistency.md +74 -0
  32. package/dist/diffray.js +0 -338
package/README.md CHANGED
@@ -5,399 +5,1015 @@
5
5
  <h1 align="center">diffray</h1>
6
6
 
7
7
  <p align="center">
8
- <strong>Multi-agent AI code review with minimal false positives</strong>
8
+ <strong>AI code reviewer that finds real bugs in your code</strong>
9
9
  </p>
10
10
 
11
+ ## Table of Contents
12
+
13
+ **Getting Started**
14
+ - [What is diffray?](#what-is-diffray)
15
+ - [Quick Start](#quick-start) · [Quick Reference](#quick-reference)
16
+ - [Prerequisites](#prerequisites)
17
+ - [Common Commands](#common-commands)
18
+ - [How It Works](#how-it-works)
19
+
20
+ **Customization**
21
+ - [Configuration](#configuration-optional)
22
+ - [Creating Custom Agents](#creating-custom-agents)
23
+ - [Creating Custom Rules](#creating-custom-rules)
24
+ - [Overriding Agents and Rules](#overriding-agents-and-rules)
25
+
26
+ **Reference**
27
+ - [FAQ](#faq)
28
+ - [Development](#development)
29
+ - [Contributing](CONTRIBUTING.md)
30
+ - [Changelog](CHANGELOG.md)
31
+
32
+ ---
33
+
34
+ > **Note:** This is a lightweight, open-source version of diffray. While inspired by the [diffray.ai](https://diffray.ai) platform, it differs significantly from the full cloud solution. The main difference is the lack of automatic feedback collection and rule generation based on your team's review history — though you can implement custom rules yourself. Thanks to powerful CLI agents like [Claude Code](https://github.com/anthropics/claude-code) and [Cursor Agent](https://cursor.com), this version can perform code reviews at a professional level. However, be aware that token consumption can grow significantly with many rules and changed files.
35
+
36
+ ## What is diffray?
37
+
38
+ diffray automatically reviews your code changes and finds bugs, security issues, and performance problems **before** you commit or create a PR.
39
+
40
+ Think of it as having a senior developer review your code 24/7.
41
+
11
42
  ```
12
- Git DiffsSpecialized AgentsDeduplication Validation Verified Issues
43
+ You write code diffray analyzes it You get a list of issues to fix
13
44
  ```
14
45
 
15
- ## About This Version
46
+ ### What it finds:
16
47
 
17
- This is a **simplified, lightweight version** of the full [diffray.ai](https://diffray.ai) platform and it's **completely free**.
48
+ - **Bugs** - logic errors, null pointer exceptions, race conditions
49
+ - **Security issues** - SQL injection, XSS, exposed secrets
50
+ - **Performance problems** - memory leaks, slow queries, unnecessary re-renders
18
51
 
19
- Despite its minimal footprint, it achieves **high bug detection rates** and **low false positive noise** by leveraging **Claude Code** as the primary executor.
52
+ ### Example output:
20
53
 
21
- Claude Code provides:
22
- - **Deep codebase understanding** - full file access and navigation
23
- - **Context-aware analysis** - reads related files to understand impact
24
- - **Accurate issue validation** - verifies findings against actual code
54
+ ```
55
+ diffray - AI Code Review
25
56
 
26
- The result: fewer false alarms, more actionable findings.
57
+ Found 2 issues:
58
+
59
+ ┌─────────────────────────────────────────────────────────────────────────────┐
60
+ │ CRITICAL | security | src/api/auth.ts:45 │
61
+ ├─────────────────────────────────────────────────────────────────────────────┤
62
+ │ SQL Injection vulnerability │
63
+ │ │
64
+ │ User input is directly concatenated into SQL query without sanitization. │
65
+ │ An attacker could execute arbitrary SQL commands. │
66
+ │ │
67
+ │ Suggestion: Use parameterized queries instead of string concatenation │
68
+ └─────────────────────────────────────────────────────────────────────────────┘
69
+
70
+ ┌─────────────────────────────────────────────────────────────────────────────┐
71
+ │ HIGH | bug | src/utils/parser.ts:23 │
72
+ ├─────────────────────────────────────────────────────────────────────────────┤
73
+ │ Possible null pointer exception │
74
+ │ │
75
+ │ data.user can be undefined, but .name is accessed without null check. │
76
+ │ │
77
+ │ Suggestion: Add optional chaining: data.user?.name │
78
+ └─────────────────────────────────────────────────────────────────────────────┘
79
+
80
+ ✓ Review completed in 12s
81
+ ```
27
82
 
28
- ## Why diffray?
83
+ ## Quick Start
29
84
 
30
- ### Multi-Agent Architecture
31
- Each agent is a specialist focused on one domain:
32
- - **security-scan** - finds vulnerabilities with concrete attack paths
33
- - **bug-hunter** - detects logic errors and runtime issues
34
- - **performance-check** - identifies performance bottlenecks
85
+ ### 1. Install diffray
35
86
 
36
- Specialized agents produce higher quality findings than one generalist trying to catch everything.
87
+ ```bash
88
+ # Install globally from npm
89
+ npm install -g diffray
90
+ ```
37
91
 
38
- ### Minimal False Positives
39
- Two-stage filtering eliminates noise:
40
- 1. **Deduplication** - removes duplicate issues across agents
41
- 2. **Validation** - LLM verifies each issue against actual code, filters out false positives
92
+ ### 2. Run your first review
42
93
 
43
- Only issues that are verified with 90%+ confidence make it to the final report.
94
+ ```bash
95
+ # Go to your project
96
+ cd your-project
44
97
 
45
- ### Flexible Execution
46
- Agents can run via different executors:
47
- - **claude-cli** - Claude Code with file access for deep analysis
48
- - **cerebras-api** - Fast Cerebras API for quick checks
49
- - Mix and match based on cost, speed, and capability needs
98
+ # Review your uncommitted changes (or last commit if working tree is clean)
99
+ diffray
50
100
 
51
- ## Key Features
101
+ # Or review changes between branches
102
+ diffray --base main
103
+ ```
52
104
 
53
- - **Multi-agent pipeline** - Specialized agents for security, bugs, performance
54
- - **False positive filtering** - Validation stage verifies issues against actual code
55
- - **Parallel execution** - All agents run simultaneously
56
- - **Rule matching** - Run different agents on different file types
57
- - **Markdown config** - Define agents and rules in simple `.md` files
58
- - **Global CLI** - Works in any git repository
59
- - **Zero config** - Sensible defaults, customize when needed
105
+ That's it! diffray will analyze your changes and show any issues found.
60
106
 
61
- ## Get Results in Your PRs
107
+ ### Quick Reference
62
108
 
63
- Want automated code reviews directly in your GitHub Pull Requests?
109
+ | Command | What it does |
110
+ |---------|--------------|
111
+ | `diffray` | Review uncommitted changes (or last commit if clean) |
112
+ | `diffray --base main` | Review changes vs main branch |
113
+ | `diffray --severity critical,high` | Show only critical/high issues |
114
+ | `diffray --agent bug-hunter` | Run only specific agent |
115
+ | `diffray --json` | Output as JSON (for CI/CD) |
116
+ | `diffray agents` | List available agents |
117
+ | `diffray rules` | List available rules |
64
118
 
65
- **Sign up at [diffray.ai](https://diffray.ai)** - connect your repo and get AI code review comments on every PR.
119
+ ## Prerequisites
66
120
 
67
- The hosted version includes:
68
- - **50+ specialized rules** for TypeScript, Python, Go, Rust, and more
69
- - **Language-specific agents** tuned for each ecosystem
70
- - **GitHub integration** - comments appear directly on PR diffs
71
- - **Team dashboard** - track issues across repositories
121
+ - **Git** - your project must be a git repository
122
+ - **AI CLI Tool** - diffray uses external AI tools to analyze code. You need to install and authorize one of them:
72
123
 
73
- ## Installation (CLI)
124
+ ### Claude Code CLI (default)
74
125
 
75
- ### From source
126
+ Claude Code is an official Anthropic CLI tool with agentic capabilities.
76
127
 
77
128
  ```bash
78
- # Clone and install
79
- git clone <your-repo>
80
- cd diffray
81
- bun install
129
+ # Install
130
+ npm install -g @anthropic-ai/claude-code
82
131
 
83
- # Link globally
84
- bun link
132
+ # Authorize (opens browser for OAuth)
133
+ claude auth login
85
134
  ```
86
135
 
87
- Now you can use `diffray` anywhere!
136
+ ### Cursor Agent CLI (alternative)
88
137
 
89
- ## Usage
138
+ If you use Cursor IDE, you can use its agent CLI instead:
90
139
 
91
- ### Run Pipeline
140
+ ```bash
141
+ # Install
142
+ curl https://cursor.com/install -fsS | bash
143
+
144
+ # Authorize (opens browser)
145
+ cursor-agent auth
146
+ ```
147
+
148
+ Then switch diffray to use it:
149
+
150
+ ```bash
151
+ # Via config
152
+ diffray config init
153
+ # Edit .diffray.json and add: "executor": "cursor-agent-cli"
154
+
155
+ # Or per-run
156
+ diffray review --executor cursor-agent-cli
157
+ ```
158
+
159
+ ### ⚠️ Token Usage & Costs
160
+
161
+ **Important:** diffray consumes AI tokens during analysis. Each review typically uses:
162
+
163
+ | Review size | Tokens | Estimated cost |
164
+ |-------------|--------|----------------|
165
+ | Small (1-5 files) | ~10-50K | $0.01-0.05 |
166
+ | Medium (5-20 files) | ~50-200K | $0.05-0.20 |
167
+ | Large (20+ files) | ~200K+ | $0.20+ |
168
+
169
+ Costs depend on your AI provider's pricing. Claude Code uses your Anthropic account or Claude Pro subscription. Cursor Agent uses your Cursor subscription.
170
+
171
+ **Tips to reduce costs:**
172
+ - Review smaller changesets more frequently
173
+ - Use `--agent` flag to run only specific agents
174
+ - Use `--skip-validation` to skip the validation stage (faster but more false positives)
175
+
176
+ ## Common Commands
92
177
 
93
178
  ```bash
94
- # Run code review pipeline
179
+ # Review uncommitted changes, or last commit if clean (most common)
95
180
  diffray
96
181
 
97
- # Output:
98
- # ⚡ diffray - AI Code Review
99
- #
100
- # Analyzing changes...
101
- # 8 files: 7 modified, 1 added
102
- # 624 changes: +612 -12
103
- # Loading agents...
104
- # Loaded 2 agent(s)
105
- #
106
- # Running 2 agent(s) in parallel...
107
- # ✓ Custom Code Review (101ms)
108
- # ✓ Security Scanner (101ms)
109
- #
110
- # ✓ Pipeline completed successfully in 102ms
111
- # ■ 2/2 agents succeeded
112
-
113
- # Verbose mode (shows file details and prompts)
114
- diffray --verbose
115
-
116
- # JSON output (machine-readable)
182
+ # Review changes compared to main branch
183
+ diffray --base main
184
+
185
+ # Review last 3 commits
186
+ diffray --base HEAD~3
187
+
188
+ # Show only critical and high severity issues
189
+ diffray --severity critical,high
190
+
191
+ # Output as JSON (for CI/CD pipelines)
117
192
  diffray --json
118
193
 
119
- # Filter by severity (show only critical)
120
- diffray --severity=critical
194
+ # Show detailed progress
195
+ diffray --stream
196
+ ```
121
197
 
122
- # Filter by multiple severities (critical and high)
123
- diffray --severity=critical,high
198
+ ## How It Works
124
199
 
125
- # Combine options
126
- diffray --json --severity=critical
200
+ ### Pipeline
127
201
 
128
- # Output includes:
129
- # ~ README.md: +141 -5
130
- # ~ src/cli.ts: +107 -3
131
- # + src/config.test.ts: +52 -0
132
- # ...
133
202
  ```
203
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
204
+ │ Git Diffs │───▶│ Match Rules │───▶│ Run Agents │───▶│ Deduplicate│
205
+ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
206
+ │ │
207
+ ▼ ▼
208
+ ┌─────────────┐ ┌─────────────┐
209
+ │ Agent 1 │ │ Validate │
210
+ │ Agent 2 │ │ (filter │
211
+ │ Agent 3 │ │ false +) │
212
+ │ ... │ └─────────────┘
213
+ └─────────────┘ │
214
+
215
+ ┌─────────────┐
216
+ │ Report │
217
+ └─────────────┘
218
+ ```
219
+
220
+ ### Agents
134
221
 
135
- ### Manage Agents
222
+ diffray uses multiple specialized AI "agents" that each focus on one type of problem:
223
+
224
+ | Agent | What it finds |
225
+ |-------|---------------|
226
+ | `general` | Code quality, readability, simplicity issues |
227
+ | `bug-hunter` | Logic errors, null checks, edge cases |
228
+ | `security-scan` | Vulnerabilities, exposed secrets |
229
+ | `performance-check` | Memory leaks, slow code |
230
+ | `consistency-check` | Inconsistent patterns, naming conventions |
231
+
232
+ Each agent analyzes your code independently, then results are:
233
+ 1. **Deduplicated** - remove duplicates if multiple agents found the same issue
234
+ 2. **Validated** - AI double-checks each issue to filter out false alarms
235
+
236
+ Only verified issues are shown in the final report.
237
+
238
+ > **Want to understand the architecture?** See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for details on agents, executors, and the stage pipeline.
239
+
240
+ ## Configuration (Optional)
241
+
242
+ diffray works out of the box with sensible defaults. But you can customize it:
243
+
244
+ ### Disable an agent
245
+
246
+ Create `.diffray.json` in your project:
247
+
248
+ ```json
249
+ {
250
+ "agents": {
251
+ "performance-check": { "enabled": false }
252
+ }
253
+ }
254
+ ```
255
+
256
+ ### Exclude files from review
257
+
258
+ ```json
259
+ {
260
+ "excludePatterns": [
261
+ "*.test.ts",
262
+ "*.spec.ts",
263
+ "generated/**"
264
+ ]
265
+ }
266
+ ```
267
+
268
+ ### Typical project configuration
269
+
270
+ Here's a practical `.diffray.json` for a TypeScript/React project:
271
+
272
+ ```json
273
+ {
274
+ "excludePatterns": [
275
+ "**/*.test.ts",
276
+ "**/*.spec.ts",
277
+ "**/__tests__/**",
278
+ "dist/**",
279
+ "node_modules/**"
280
+ ],
281
+ "agents": {
282
+ "performance-check": { "enabled": false }
283
+ }
284
+ }
285
+ ```
286
+
287
+ ### Full configuration reference
288
+
289
+ All available options (you don't need all of these):
290
+
291
+ ```json
292
+ {
293
+ "excludePatterns": ["*.test.ts", "generated/**"],
294
+ "concurrency": 4,
295
+ "executor": "claude-cli",
296
+ "executors": {
297
+ "claude-cli": {
298
+ "review": { "model": "sonnet", "timeout": 120, "concurrency": 6 },
299
+ "validation": { "model": "opus", "timeout": 180, "batchSize": 10 }
300
+ }
301
+ },
302
+ "agents": {
303
+ "security-scan": { "enabled": false },
304
+ "bug-hunter": { "model": "haiku", "timeout": 60 }
305
+ },
306
+ "rules": {
307
+ "code-security": { "enabled": false }
308
+ },
309
+ "output": {
310
+ "colorize": true,
311
+ "verbose": false,
312
+ "format": "terminal"
313
+ }
314
+ }
315
+ ```
316
+
317
+ | Option | Description |
318
+ |--------|-------------|
319
+ | `excludePatterns` | Glob patterns for files to skip |
320
+ | `concurrency` | Global max parallel agents (1-10, default: **6**) |
321
+ | `executor` | Which executor to use (`claude-cli`, `cursor-agent-cli`) |
322
+ | `executors.<name>.<stage>` | Per-executor, per-stage settings |
323
+ | `agents.<name>` | Override agent settings (`enabled`, `model`, `timeout`) |
324
+ | `rules.<name>` | Override rule settings (`enabled`, `agent`) |
325
+
326
+ ### Concurrency settings
327
+
328
+ Concurrency controls how many agents run in parallel. Higher values = faster reviews but more API load.
329
+
330
+ **Default:** 6 parallel agents
331
+
332
+ **Two levels of configuration:**
333
+
334
+ ```json
335
+ {
336
+ "concurrency": 6,
337
+ "executors": {
338
+ "claude-cli": {
339
+ "review": { "concurrency": 6 },
340
+ "validation": { "concurrency": 3 }
341
+ }
342
+ }
343
+ }
344
+ ```
345
+
346
+ | Setting | What it controls |
347
+ |---------|------------------|
348
+ | `concurrency` | Global default for all stages |
349
+ | `executors.<name>.review.concurrency` | Parallel agents during review stage |
350
+ | `executors.<name>.validation.concurrency` | Parallel validations |
351
+
352
+ **Priority:** stage-specific > global
353
+
354
+ **Recommendations:**
355
+ - **Fast machine + good internet:** `6` (default)
356
+ - **Rate limited API:** `2-3`
357
+ - **Debugging:** `1` (sequential, easier to read logs)
358
+
359
+ ### Config commands
136
360
 
137
361
  ```bash
138
- # List all agents
139
- diffray agents list
362
+ # Create config file
363
+ diffray config init
364
+
365
+ # Edit config in your editor
366
+ diffray config edit
140
367
 
141
- # Show agent details
142
- diffray agents show bug-hunter
368
+ # Show current config
369
+ diffray config show
143
370
  ```
144
371
 
145
- **Creating Custom Agents:**
372
+ ## Creating Custom Agents
373
+
374
+ You can create your own agents to check for anything you want! Agents are simple Markdown files.
375
+
376
+ ### Where to put agent files
377
+
378
+ | Location | When to use |
379
+ |----------|-------------|
380
+ | `~/.diffray/agents/` | Your personal agents (work in all projects) |
381
+ | `.diffray/agents/` | Project-specific agents (share with team via git) |
382
+
383
+ ### Agent file format
146
384
 
147
- Agents are defined using Markdown files! See [Agent Configuration Guide](./docs/AGENTS.md) for details.
385
+ Each agent is a `.md` file with two parts:
148
386
 
149
- Create a new `.md` file in `~/.diffray/agents/` or `.diffray/agents/` with frontmatter and a system prompt.
387
+ 1. **Header** (between `---` lines) - settings in YAML format
388
+ 2. **Body** - instructions for the AI (what to look for)
150
389
 
151
- ### Manage Executors
390
+ ### Step-by-step: Create your first agent
391
+
392
+ **Step 1.** Create the folder (if it doesn't exist):
152
393
 
153
394
  ```bash
154
- # List all executors
155
- diffray executors list
395
+ mkdir -p ~/.diffray/agents
396
+ ```
397
+
398
+ **Step 2.** Create a new file `~/.diffray/agents/my-rules.md`:
399
+
400
+ ```markdown
401
+ ---
402
+ name: my-rules
403
+ description: Checks for my team's coding standards
404
+ enabled: true
405
+ ---
406
+
407
+ You are a code reviewer checking for our team's coding standards.
408
+
409
+ ## What to check:
156
410
 
157
- # Show executor details
158
- diffray executors show claude-cli
411
+ 1. **No console.log** - All console.log statements should be removed before commit
412
+ 2. **Function comments** - All exported functions must have a description comment
413
+ 3. **Error handling** - All async functions must have try/catch blocks
414
+ 4. **Naming** - Variables should have meaningful names (no single letters except in loops)
159
415
 
160
- # Enable/disable executors
161
- diffray executors enable cerebras-api
162
- diffray executors disable claude-cli
416
+ ## How to report:
417
+
418
+ - Only report clear violations
419
+ - Be specific about what line and what's wrong
420
+ - Suggest how to fix it
421
+ ```
422
+
423
+ **Step 3.** Verify your agent is loaded:
424
+
425
+ ```bash
426
+ diffray agents
163
427
  ```
164
428
 
165
- ### Manage Rules
429
+ You should see `my-rules` in the list.
166
430
 
167
- Rules allow you to run different agents on different file types using glob patterns. Rules are defined in Markdown files.
431
+ **Step 4.** Run a review - your agent will now analyze your code!
168
432
 
169
433
  ```bash
170
- # List all rules
171
- diffray rules list
434
+ diffray
435
+ ```
172
436
 
173
- # Show rule details
174
- diffray rules show code-bugs
437
+ ### Header fields explained
438
+
439
+ ```yaml
440
+ ---
441
+ name: my-rules # Unique ID (lowercase, use dashes)
442
+ description: What it does # Short description
443
+ enabled: true # Set to false to disable temporarily
444
+ order: 10 # Lower = runs first (optional, default: 0)
445
+ ---
446
+ ```
447
+
448
+ ### Example agents
449
+
450
+ #### React best practices checker
451
+
452
+ ```markdown
453
+ ---
454
+ name: react-checker
455
+ description: Checks React code for common mistakes
456
+ enabled: true
457
+ ---
458
+
459
+ You are a React expert reviewing code for common mistakes.
460
+
461
+ ## Check for:
462
+
463
+ 1. **Missing keys in lists** - All .map() rendering elements need unique key props
464
+ 2. **useEffect dependencies** - Missing dependencies in useEffect arrays
465
+ 3. **State mutations** - Direct state mutations instead of setState
466
+ 4. **Memory leaks** - Missing cleanup in useEffect (event listeners, subscriptions)
467
+
468
+ ## Ignore:
469
+ - Styling preferences
470
+ - Minor formatting issues
471
+ ```
472
+
473
+ #### API security checker
474
+
475
+ ```markdown
476
+ ---
477
+ name: api-security
478
+ description: Checks API endpoints for security issues
479
+ enabled: true
480
+ ---
481
+
482
+ You are a security engineer reviewing API code.
483
+
484
+ ## Check for:
485
+
486
+ 1. **Missing authentication** - Endpoints without auth checks
487
+ 2. **SQL injection** - User input in SQL queries without parameterization
488
+ 3. **Missing rate limiting** - Public endpoints without rate limits
489
+ 4. **Exposed secrets** - API keys, passwords, tokens in code
490
+
491
+ ## Report format:
492
+ - Severity: CRITICAL for exploitable issues, HIGH for potential issues
493
+ - Include the specific line and code snippet
494
+ - Explain the attack vector
495
+ - Provide a fix
496
+ ```
497
+
498
+ #### TypeScript strict checker
499
+
500
+ ```markdown
501
+ ---
502
+ name: typescript-strict
503
+ description: Enforces strict TypeScript practices
504
+ enabled: true
505
+ ---
506
+
507
+ You are a TypeScript expert checking for type safety.
508
+
509
+ ## Check for:
510
+
511
+ 1. **any type** - Usage of 'any' type (should be specific type or 'unknown')
512
+ 2. **Type assertions** - Unnecessary 'as' casts that could hide errors
513
+ 3. **Missing null checks** - Accessing properties that could be null/undefined
514
+ 4. **Implicit any** - Function parameters without type annotations
175
515
 
176
- # Test rule matching against specific files
177
- diffray rules test code-bugs src/cli.ts src/agents.ts README.md
178
- # Output:
179
- # ✓ Matched 2 file(s):
180
- # ● src/cli.ts
181
- # ● src/agents.ts
182
- # Not matched 1 file(s):
183
- # ○ README.md
516
+ ## Ignore:
517
+ - Third-party library types
518
+ - Test files
184
519
  ```
185
520
 
186
- **Creating Custom Rules:**
521
+ ### Tips for writing good agents
187
522
 
188
- Create a new `.md` file in `~/.diffray/rules/` or `.diffray/rules/` with frontmatter:
523
+ 1. **Be specific** - "Check for console.log" is better than "check for debug code"
524
+ 2. **Give examples** - Show what bad code looks like
525
+ 3. **Set priorities** - Tell the AI what's important vs minor
526
+ 4. **Define what to ignore** - Reduce false positives
527
+
528
+ ### Managing agents
529
+
530
+ ```bash
531
+ # List all agents (shows name, description, enabled status)
532
+ diffray agents
533
+
534
+ # Show full details of an agent
535
+ diffray agents bug-hunter
536
+
537
+ # Disable an agent via config (without deleting the file)
538
+ # Add to .diffray.json:
539
+ {
540
+ "agents": {
541
+ "my-rules": { "enabled": false }
542
+ }
543
+ }
544
+ ```
545
+
546
+ ### Troubleshooting
547
+
548
+ **Agent not showing up?**
549
+ - Check file has `.md` extension
550
+ - Check file is in correct folder (`~/.diffray/agents/` or `.diffray/agents/`)
551
+ - Check YAML header syntax (must be between `---` lines)
552
+
553
+ **Agent not finding issues?**
554
+ - Make instructions more specific
555
+ - Add examples of what to look for
556
+ - Check `enabled: true` in header
557
+
558
+ ## Creating Custom Rules
559
+
560
+ Rules connect agents to files. They tell diffray: "Run this agent on these files".
561
+
562
+ ### What are rules?
563
+
564
+ By default, diffray runs ALL agents on ALL changed files. But with rules you can:
565
+
566
+ - Run `security-scan` agent **only** on `*.ts` files
567
+ - Run `python-checker` agent **only** on `*.py` files
568
+ - Add extra instructions for specific file types
569
+
570
+ ### Where to put rule files
571
+
572
+ | Location | When to use |
573
+ |----------|-------------|
574
+ | `~/.diffray/rules/` | Your personal rules (work in all projects) |
575
+ | `.diffray/rules/` | Project-specific rules (share with team via git) |
576
+
577
+ ### Rule file format
578
+
579
+ Rules are also Markdown files with a header:
189
580
 
190
581
  ```markdown
191
582
  ---
192
- name: my-rule
193
- description: Description of what this rule does
583
+ name: frontend-bugs
584
+ description: Bug detection for React frontend
194
585
  patterns:
195
- - "**/*.ts"
196
- - "**/*.tsx"
586
+ - "src/components/**/*.tsx"
587
+ - "src/hooks/**/*.ts"
197
588
  agent: bug-hunter
198
589
  ---
199
590
 
200
- Additional instructions for the agent when this rule matches.
591
+ Extra instructions for this rule (optional).
592
+
593
+ Focus on React-specific issues like:
594
+ - Missing useCallback/useMemo
595
+ - Incorrect dependency arrays
201
596
  ```
202
597
 
203
- **Default Rules:**
204
- - `code-bugs`: Run bug-hunter on code files `**/*.{ts,tsx,js,jsx,py,go,rs,java,rb,php}`
205
- - `code-security`: Run security-scan on code files `**/*.{ts,tsx,js,jsx,py,go,rs,java,rb,php}`
206
- - `config-security`: Run security-scan on config files `**/*.{json,yaml,yml,toml}`
598
+ ### Step-by-step: Create your first rule
207
599
 
208
- ### Configuration
600
+ **Step 1.** Create the folder:
209
601
 
210
- diffray stores configuration in `~/.diffray/config.json`. This file stores executor settings and other preferences.
602
+ ```bash
603
+ mkdir -p ~/.diffray/rules
604
+ ```
605
+
606
+ **Step 2.** Create `~/.diffray/rules/python-security.md`:
607
+
608
+ ```markdown
609
+ ---
610
+ name: python-security
611
+ description: Security checks for Python files
612
+ patterns:
613
+ - "**/*.py"
614
+ agent: security-scan
615
+ ---
616
+
617
+ Focus on Python-specific security issues:
618
+
619
+ 1. **eval() and exec()** - Dynamic code execution
620
+ 2. **pickle** - Insecure deserialization
621
+ 3. **subprocess** - Command injection via shell=True
622
+ 4. **SQL** - String formatting in SQL queries
623
+ 5. **YAML** - yaml.load() without safe_load
624
+ ```
625
+
626
+ **Step 3.** Verify your rule is loaded:
211
627
 
212
628
  ```bash
213
- # Initialize configuration file
214
- diffray config init
629
+ diffray rules
630
+ ```
215
631
 
216
- # Show current configuration
217
- diffray config show
632
+ **Step 4.** Test which files match your rule:
218
633
 
219
- # Edit configuration in your $EDITOR
220
- diffray config edit
634
+ ```bash
635
+ diffray rules python-security --test src/
636
+ ```
221
637
 
222
- # Reset to defaults
223
- diffray config reset
638
+ ### Header fields explained
639
+
640
+ ```yaml
641
+ ---
642
+ name: python-security # Unique ID (lowercase, use dashes)
643
+ description: What it does # Short description
644
+ patterns: # Which files to match (glob patterns)
645
+ - "**/*.py" # All Python files
646
+ - "scripts/*.sh" # Shell scripts in scripts/ folder
647
+ agent: security-scan # Which agent to run on matched files
648
+ ---
224
649
  ```
225
650
 
226
- #### Configuration Structure
651
+ ### Understanding patterns (glob syntax)
227
652
 
228
- The configuration file has the following structure:
653
+ Patterns use "glob" syntax to match files:
229
654
 
230
- ```json
655
+ | Pattern | What it matches |
656
+ |---------|-----------------|
657
+ | `*.ts` | All `.ts` files in root folder only |
658
+ | `**/*.ts` | All `.ts` files in any folder |
659
+ | `src/**/*.ts` | All `.ts` files inside `src/` folder |
660
+ | `src/*.ts` | Only `.ts` files directly in `src/` (not subfolders) |
661
+ | `**/*.{ts,tsx}` | All `.ts` and `.tsx` files |
662
+ | `!**/*.test.ts` | Exclude test files (prefix with `!`) |
663
+
664
+ ### Example rules
665
+
666
+ #### Backend API security
667
+
668
+ ```markdown
669
+ ---
670
+ name: api-security
671
+ description: Security review for API endpoints
672
+ patterns:
673
+ - "src/api/**/*.ts"
674
+ - "src/routes/**/*.ts"
675
+ - "src/controllers/**/*.ts"
676
+ agent: security-scan
677
+ ---
678
+
679
+ Focus on API security:
680
+
681
+ 1. Check authentication on all endpoints
682
+ 2. Validate all user input
683
+ 3. Check for SQL/NoSQL injection
684
+ 4. Verify rate limiting
685
+ 5. Check CORS configuration
686
+ ```
687
+
688
+ #### React components quality
689
+
690
+ ```markdown
691
+ ---
692
+ name: react-quality
693
+ description: Quality checks for React components
694
+ patterns:
695
+ - "src/components/**/*.tsx"
696
+ - "src/pages/**/*.tsx"
697
+ agent: bug-hunter
698
+ ---
699
+
700
+ Focus on React best practices:
701
+
702
+ 1. Missing key props in lists
703
+ 2. useEffect dependency arrays
704
+ 3. Memory leaks (missing cleanup)
705
+ 4. Prop types validation
706
+ 5. Conditional rendering bugs
707
+ ```
708
+
709
+ #### Config files security
710
+
711
+ ```markdown
712
+ ---
713
+ name: config-security
714
+ description: Check config files for exposed secrets
715
+ patterns:
716
+ - "**/*.json"
717
+ - "**/*.yaml"
718
+ - "**/*.yml"
719
+ - "**/*.env.example"
720
+ agent: security-scan
721
+ ---
722
+
723
+ Check for:
724
+
725
+ 1. Hardcoded API keys or tokens
726
+ 2. Database credentials
727
+ 3. Private keys
728
+ 4. Sensitive URLs
729
+ ```
730
+
731
+ #### Documentation checker
732
+
733
+ ```markdown
734
+ ---
735
+ name: docs-quality
736
+ description: Check documentation for issues
737
+ patterns:
738
+ - "**/*.md"
739
+ - "docs/**/*"
740
+ agent: general
741
+ ---
742
+
743
+ Check documentation for:
744
+
745
+ 1. Broken links
746
+ 2. Outdated code examples
747
+ 3. Missing sections
748
+ 4. Typos in commands
749
+ ```
750
+
751
+ ### Default rules (built-in)
752
+
753
+ diffray comes with these rules out of the box:
754
+
755
+ | Rule | Files | Agent |
756
+ |------|-------|-------|
757
+ | `code-general` | `*.ts, *.js, *.py, *.go, *.rs, *.java, *.rb, *.php, ...` | `general` |
758
+ | `code-bugs` | Same as above | `bug-hunter` |
759
+ | `code-security` | Same as above | `security-scan` |
760
+ | `code-performance` | Same as above | `performance-check` |
761
+ | `code-consistency` | Same as above + `*.md, *.json, *.yaml` | `consistency-check` |
762
+ | `config-security` | `*.json, *.yaml, *.yml, *.toml` | `security-scan` |
763
+
764
+ ### Managing rules
765
+
766
+ ```bash
767
+ # List all rules
768
+ diffray rules
769
+
770
+ # Show rule details
771
+ diffray rules code-bugs
772
+
773
+ # Test which files a rule matches
774
+ diffray rules code-bugs --test src/
775
+
776
+ # Disable a rule via config
777
+ # Add to .diffray.json:
231
778
  {
232
- "excludePatterns": ["*.lock", "*.min.js", "dist/*", "node_modules/**"],
233
- "output": {
234
- "colorize": true,
235
- "verbose": false,
236
- "format": "terminal"
237
- },
238
- "executors": [...],
239
- "stages": [...]
779
+ "rules": {
780
+ "code-performance": { "enabled": false }
781
+ }
240
782
  }
241
783
  ```
242
784
 
243
- **Key Sections:**
785
+ ### Rules vs Agents: What's the difference?
786
+
787
+ | | Agent | Rule |
788
+ |---|-------|------|
789
+ | **What** | The AI reviewer (what to check) | The file filter (where to check) |
790
+ | **Contains** | Instructions for AI | File patterns + which agent to use |
791
+ | **Example** | "Check for SQL injection" | "Run security-scan on *.py files" |
792
+
793
+ **Think of it this way:**
794
+ - **Agent** = The inspector (knows what problems to look for)
795
+ - **Rule** = The assignment (tells inspector which rooms to check)
244
796
 
245
- - `excludePatterns`: File patterns to exclude from review (array of glob patterns)
246
- - `output.colorize`: Enable colored output (boolean, default: `true`)
247
- - `output.verbose`: Show verbose output (boolean, default: `false`)
248
- - `output.format`: Output format - `terminal`, `markdown`, or `json` (default: `terminal`)
249
- - `executors`: Executor configurations (managed via `diffray executors` commands)
250
- - `stages`: Pipeline stage configurations with enabled/disabled status
797
+ ### Troubleshooting
251
798
 
252
- **Dynamic Data (loaded from MD files on each run):**
253
- - `agents`: Loaded from `~/.diffray/agents/`, `.diffray/agents/`, `src/defaults/agents/`
254
- - `rules`: Loaded from `~/.diffray/rules/`, `.diffray/rules/`, `src/defaults/rules/`
799
+ **Rule not matching files?**
800
+ - Check pattern syntax (use `**/*.ts` not `*.ts` for recursive)
801
+ - Test with `diffray rules your-rule --test path/`
802
+ - Remember patterns are relative to project root
255
803
 
256
- ### Executors Configuration
804
+ **Agent not running on expected files?**
805
+ - Make sure rule's `agent` field matches an existing agent name
806
+ - Check that both rule and agent have `enabled: true`
257
807
 
258
- Executors define **how** to run Agents. diffray supports multiple executor types:
808
+ ## Overriding Agents and Rules
259
809
 
260
- - **CLI Executors** - Run CLI tools like `claude`, `auggie`, etc.
261
- - **LLM API Executors** - Call LLM APIs directly (Claude, GPT, etc.)
810
+ You can override built-in agents and rules without editing their original files. This is useful when you want to:
262
811
 
263
- Executors are configured in `~/.diffray/config.json`.
812
+ - Disable a built-in agent or rule
813
+ - Change settings for a specific project
814
+ - Override agent's model or timeout
264
815
 
265
- #### Executor Configuration
816
+ ### Override via config file
266
817
 
267
- Executors can be configured in `~/.diffray/config.json`:
818
+ Create `.diffray.json` in your project root:
268
819
 
269
820
  ```json
270
821
  {
271
- "executors": [
272
- {
273
- "name": "claude-cli",
274
- "enabled": true,
275
- "model": "opus",
276
- "timeout": 180
277
- },
278
- {
279
- "name": "cerebras-api",
280
- "enabled": true,
281
- "model": "llama-3.1-8b",
282
- "temperature": 0.5,
283
- "maxTokens": 4096
284
- }
285
- ]
822
+ "agents": {
823
+ "performance-check": { "enabled": false },
824
+ "bug-hunter": { "model": "opus", "timeout": 180 }
825
+ },
826
+ "rules": {
827
+ "code-security": { "enabled": false },
828
+ "code-bugs": { "agent": "my-custom-agent" }
829
+ }
286
830
  }
287
831
  ```
288
832
 
289
- #### Executor Options
833
+ ### Agent overrides
290
834
 
291
- **CLI Executors (claude-cli):**
292
- - `enabled` - Enable/disable executor
293
- - `model` - Model to use (default: `sonnet`)
294
- - `timeout` - Timeout in seconds (default: 120)
835
+ | Field | What it does | Example |
836
+ |-------|--------------|---------|
837
+ | `enabled` | Turn agent on/off | `{ "enabled": false }` |
838
+ | `model` | Use different AI model | `{ "model": "opus" }` |
839
+ | `timeout` | Increase timeout (seconds) | `{ "timeout": 300 }` |
295
840
 
296
- **API Executors (cerebras-api):**
297
- - `enabled` - Enable/disable executor
298
- - `model` - Model to use (default: `llama-3.3-70b`)
299
- - `temperature` - Temperature (default: 0.7)
300
- - `maxTokens` - Max tokens (default: 8192)
841
+ ### Rule overrides
301
842
 
302
- #### Linking Agents to Executors
843
+ | Field | What it does | Example |
844
+ |-------|--------------|---------|
845
+ | `enabled` | Turn rule on/off | `{ "enabled": false }` |
846
+ | `agent` | Use different agent | `{ "agent": "my-agent" }` |
303
847
 
304
- Agents reference executors via the `executor` field in their Markdown configuration:
848
+ ### Override by creating your own file
305
849
 
306
- ```markdown
307
- ---
308
- name: bug-hunter
309
- executor: claude-cli
310
- ---
311
- ```
850
+ If a file with the same `name` exists in a higher-priority folder, it overrides the lower one.
312
851
 
313
- ## Agent Configuration
852
+ **Priority order (highest to lowest):**
853
+ 1. `.diffray/agents/` or `.diffray/rules/` (project folder)
854
+ 2. `~/.diffray/agents/` or `~/.diffray/rules/` (home folder)
855
+ 3. Built-in defaults
314
856
 
315
- Agents are configured using **Markdown files** in `src/defaults/agents/`. See the [Agent Configuration Guide](./docs/AGENTS.md) for complete documentation.
857
+ **Example:** To override the built-in `bug-hunter` agent, create:
316
858
 
317
- ### Agent Markdown Format
859
+ ```bash
860
+ # Create project-specific override
861
+ mkdir -p .diffray/agents
862
+ ```
318
863
 
319
- Each agent is defined in a `.md` file with frontmatter metadata:
864
+ Then create `.diffray/agents/bug-hunter.md`:
320
865
 
321
866
  ```markdown
322
867
  ---
323
868
  name: bug-hunter
324
- description: Detects bugs, logic errors and runtime issues
869
+ description: My custom bug hunter
325
870
  enabled: true
326
- executor: claude-cli
327
871
  ---
328
872
 
329
- You are a code reviewer analyzing changes for:
873
+ Your completely custom instructions here...
874
+ ```
875
+
876
+ Now your version will be used instead of the built-in one.
877
+
878
+ ### Common override scenarios
879
+
880
+ #### Disable security scanning for a project
881
+
882
+ ```json
883
+ {
884
+ "agents": {
885
+ "security-scan": { "enabled": false }
886
+ },
887
+ "rules": {
888
+ "code-security": { "enabled": false },
889
+ "config-security": { "enabled": false }
890
+ }
891
+ }
892
+ ```
893
+
894
+ #### Use faster model for development
895
+
896
+ ```json
897
+ {
898
+ "agents": {
899
+ "bug-hunter": { "model": "haiku" },
900
+ "security-scan": { "model": "haiku" }
901
+ }
902
+ }
903
+ ```
904
+
905
+ #### Only run bug checking (disable everything else)
906
+
907
+ ```json
908
+ {
909
+ "agents": {
910
+ "security-scan": { "enabled": false },
911
+ "performance-check": { "enabled": false }
912
+ },
913
+ "rules": {
914
+ "code-security": { "enabled": false },
915
+ "code-performance": { "enabled": false },
916
+ "config-security": { "enabled": false }
917
+ }
918
+ }
919
+ ```
330
920
 
331
- ### Logic Errors
332
- - Identify bugs and edge cases
333
- - Check error handling
921
+ #### Increase timeout for large files
334
922
 
335
- ### Code Quality
336
- - Assess readability
337
- - Check naming conventions
923
+ ```json
924
+ {
925
+ "agents": {
926
+ "bug-hunter": { "timeout": 300 },
927
+ "security-scan": { "timeout": 300 }
928
+ }
929
+ }
338
930
  ```
339
931
 
340
- The system automatically loads all `.md` files from `~/.diffray/agents/`, `.diffray/agents/`, and `src/defaults/agents/`.
932
+ ## FAQ
933
+
934
+ ### Why is it slow?
341
935
 
342
- ## Example Output
936
+ diffray uses Claude AI which takes time to analyze code properly. Typical review takes 10-30 seconds. For faster (but less accurate) reviews, use:
343
937
 
938
+ ```bash
939
+ diffray --skip-validation
344
940
  ```
345
- ⚡ diffray - AI Code Review
346
941
 
347
- Analyzing changes...
942
+ ### Why didn't it find an obvious bug?
943
+
944
+ AI isn't perfect. diffray is tuned for **low false positives** (fewer wrong alerts) rather than finding every possible issue. If you think it missed something, please [open an issue](https://github.com/diffray/diffray/issues).
945
+
946
+ ### Can I use it in CI/CD?
947
+
948
+ Yes! Use `--json` flag for machine-readable output:
348
949
 
349
- Summary: 2 modified, 1 added
950
+ ```bash
951
+ diffray --json --severity critical,high
952
+ ```
953
+
954
+ Exit code is non-zero if issues are found.
955
+
956
+ **GitHub Actions example:**
957
+
958
+ ```yaml
959
+ name: Code Review
960
+ on: [pull_request]
350
961
 
351
- ================================================================================
962
+ jobs:
963
+ review:
964
+ runs-on: ubuntu-latest
965
+ steps:
966
+ - uses: actions/checkout@v4
967
+ with:
968
+ fetch-depth: 0
352
969
 
353
- src/index.ts (modified)
970
+ - uses: actions/setup-node@v4
971
+ with:
972
+ node-version: '20'
354
973
 
355
- + export function greet(name: string): string {
356
- + return `Hello, ${name}!`;
357
- + }
974
+ - run: npm install -g diffray @anthropic-ai/claude-code
358
975
 
359
- --------------------------------------------------------------------------------
976
+ - run: claude auth login --api-key ${{ secrets.ANTHROPIC_API_KEY }}
360
977
 
361
- Reviewed 3 file(s)
978
+ - run: diffray --base origin/${{ github.base_ref }} --json --severity critical,high
362
979
  ```
363
980
 
981
+ ### How much does it cost?
982
+
983
+ The CLI is free, but uses Claude AI which has API costs. With Claude Code CLI, costs are typically $0.01-0.05 per review.
984
+
985
+ ## Get Results in Your PRs
986
+
987
+ Want automated reviews directly in GitHub Pull Requests?
988
+
989
+ **Sign up at [diffray.ai](https://diffray.ai)** - connect your repo and get AI review comments on every PR automatically.
990
+
364
991
  ## Development
365
992
 
366
993
  ```bash
367
- # Run in development mode
368
- bun run dev
994
+ # Clone the repo
995
+ git clone https://github.com/diffray/diffray.git
996
+ cd diffray
369
997
 
370
- # Build standalone binary
371
- bun run build
998
+ # Install dependencies
999
+ npm install
372
1000
 
373
- # Run tests
374
- bun test
375
- ```
1001
+ # Run in dev mode
1002
+ npm run dev
376
1003
 
377
- ## Project Structure
1004
+ # Run tests
1005
+ npm test
378
1006
 
1007
+ # Build
1008
+ npm run build
379
1009
  ```
380
- diffray/
381
- ├── bin/
382
- │ └── diffray.ts # CLI entry point
383
- ├── src/
384
- │ ├── cli.ts # Main CLI logic
385
- │ ├── pipeline.ts # Pipeline execution
386
- │ ├── stages/ # Pipeline stages
387
- │ ├── agents/ # Agent registry and loaders
388
- │ ├── executors/ # Executor implementations
389
- │ ├── commands/ # CLI commands
390
- │ ├── defaults/ # Default agents and rules (Markdown)
391
- │ ├── git.ts # Git operations
392
- │ └── issue-formatter.ts # Issue formatting
393
- └── package.json
394
- ```
395
-
396
- ## Built With
397
1010
 
398
- - [Bun](https://bun.sh) - Fast JavaScript runtime
399
- - TypeScript - Type safety
1011
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed development guidelines.
400
1012
 
401
1013
  ## License
402
1014
 
403
1015
  MIT
1016
+
1017
+ ---
1018
+
1019
+ **[Changelog](CHANGELOG.md)** · **[Contributing](CONTRIBUTING.md)** · **[Architecture](docs/ARCHITECTURE.md)**