diffray 0.1.3 → 0.3.1

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 +659 -259
  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 +354 -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
@@ -1,403 +1,803 @@
1
+ <table>
2
+ <tr>
3
+ <td><img src="logo.svg" alt="diffray" width="120"></td>
4
+ <td>
5
+ <h1>diffray</h1>
6
+ <strong>Free open-source multi-agent code review</strong>
7
+ </td>
8
+ </tr>
9
+ </table>
10
+
11
+ > **What is this?** A CLI tool that runs multiple AI agents to review your code changes. Each agent specializes in different aspects: bugs, security, performance, code style. Works with [Claude Code](https://github.com/anthropics/claude-code) or [Cursor Agent](https://cursor.com).
12
+ >
13
+ > **How is it different from [diffray.ai](https://diffray.ai)?** The cloud platform automatically learns from your team's review feedback and generates rules. This CLI version requires manual rule configuration but gives you full control and runs locally.
14
+
1
15
  <p align="center">
2
- <img src="logo.svg" alt="diffray" width="200">
16
+ <img src="/docs/diffray.png" alt="diffray in action" width="800">
3
17
  </p>
4
18
 
5
- <h1 align="center">diffray</h1>
19
+ ---
6
20
 
7
- <p align="center">
8
- <strong>Multi-agent AI code review with minimal false positives</strong>
9
- </p>
21
+ ## Table of Contents
22
+
23
+ - [Quick Start](#quick-start)
24
+ - [Prerequisites](#prerequisites)
25
+ - [How It Works](#how-it-works)
26
+ - [Configuration](#configuration-optional)
27
+ - [Creating Custom Agents](#creating-custom-agents)
28
+ - [Creating Custom Rules](#creating-custom-rules)
29
+ - [Overriding Agents and Rules](#overriding-agents-and-rules)
30
+ - [FAQ](#faq)
31
+ - [Development](#development)
32
+
33
+ ---
34
+
35
+ ## Quick Start
10
36
 
37
+ ### 1. Install diffray
38
+
39
+ ```bash
40
+ # Install globally from npm
41
+ npm install -g diffray
11
42
  ```
12
- Git Diffs → Specialized Agents → Deduplication → Validation → Verified Issues
43
+
44
+ ### 2. Run your first review
45
+
46
+ ```bash
47
+ # Go to your project
48
+ cd your-project
49
+
50
+ # Review your uncommitted changes (or last commit if working tree is clean)
51
+ diffray
52
+
53
+ # Or review changes between branches
54
+ diffray --base main
13
55
  ```
14
56
 
15
- ## About This Version
57
+ That's it! diffray will analyze your changes and show any issues found.
16
58
 
17
- This is a **simplified, lightweight version** of the full [diffray.ai](https://diffray.ai) platform — and it's **completely free**.
59
+ ### Common Commands
18
60
 
19
- Despite its minimal footprint, it achieves **high bug detection rates** and **low false positive noise** by leveraging **Claude Code** as the primary executor.
61
+ ```bash
62
+ # Review uncommitted changes, or last commit if clean
63
+ diffray
20
64
 
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
65
+ # Review changes compared to main branch
66
+ diffray --base main
25
67
 
26
- The result: fewer false alarms, more actionable findings.
68
+ # Review last 3 commits
69
+ diffray --base HEAD~3
27
70
 
28
- ## Why diffray?
71
+ # Show only critical and high severity issues
72
+ diffray --severity critical,high
29
73
 
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
74
+ # Run only specific agent
75
+ diffray --agent bug-hunter
35
76
 
36
- Specialized agents produce higher quality findings than one generalist trying to catch everything.
77
+ # Output as JSON (for CI/CD pipelines)
78
+ diffray --json
37
79
 
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
80
+ # Show detailed progress
81
+ diffray --stream
42
82
 
43
- Only issues that are verified with 90%+ confidence make it to the final report.
83
+ # List available agents and rules
84
+ diffray agents
85
+ diffray rules
86
+ ```
44
87
 
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
88
+ ## Prerequisites
50
89
 
51
- ## Key Features
90
+ - **Git** - your project must be a git repository
91
+ - **AI CLI Tool** - diffray uses external AI tools to analyze code. You need to install and authorize one of them:
52
92
 
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
93
+ ### Claude Code CLI (default)
60
94
 
61
- ## Get Results in Your PRs
95
+ Claude Code is an official Anthropic CLI tool with agentic capabilities.
62
96
 
63
- Want automated code reviews directly in your GitHub Pull Requests?
97
+ ```bash
98
+ # Install
99
+ npm install -g @anthropic-ai/claude-code
64
100
 
65
- **Sign up at [diffray.ai](https://diffray.ai)** - connect your repo and get AI code review comments on every PR.
101
+ # Authorize (opens browser for OAuth)
102
+ claude auth login
103
+ ```
66
104
 
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
105
+ ### Cursor Agent CLI (alternative)
72
106
 
73
- ## Installation (CLI)
107
+ If you use Cursor IDE, you can use its agent CLI instead:
74
108
 
75
- ### From source
109
+ ```bash
110
+ # Install
111
+ curl https://cursor.com/install -fsS | bash
112
+
113
+ # Authorize (opens browser)
114
+ cursor-agent
115
+ ```
116
+
117
+ Then switch diffray to use it:
76
118
 
77
119
  ```bash
78
- # Clone and install
79
- git clone <your-repo>
80
- cd diffray
81
- bun install
120
+ # Via config
121
+ diffray config init
122
+ # Edit .diffray.json and add: "executor": "cursor-agent-cli"
82
123
 
83
- # Link globally
84
- bun link
124
+ # Or per-run
125
+ diffray review --executor cursor-agent-cli
85
126
  ```
86
127
 
87
- Now you can use `diffray` anywhere!
128
+ Costs depend on your AI provider's pricing. Claude Code uses your Anthropic account or Claude Pro subscription. Cursor Agent uses your Cursor subscription.
88
129
 
89
- ## Usage
130
+ **Tips to reduce costs:**
131
+ - Review smaller changesets more frequently
132
+ - Use `--agent` flag to run only specific agents
133
+ - Use `--skip-validation` to skip the validation stage (faster but more false positives)
90
134
 
91
- ### Run Pipeline
135
+ ## How It Works
92
136
 
93
- ```bash
94
- # Run code review pipeline
95
- diffray
137
+ ### Pipeline
96
138
 
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)
117
- diffray --json
139
+ ```
140
+ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐
141
+ │ Git Diffs │───▶│ Match Rules │───▶│ Run Agents │───▶│ Deduplicate│
142
+ └─────────────┘ └─────────────┘ └─────────────┘ └─────────────┘
143
+ │ │
144
+ ▼ ▼
145
+ ┌─────────────┐ ┌─────────────┐
146
+ │ Agent 1 │ │ Validate │
147
+ │ Agent 2 │ │ (filter │
148
+ │ Agent 3 │ │ false +)
149
+ │ ... │ └─────────────┘
150
+ └─────────────┘ │
151
+
152
+ ┌─────────────┐
153
+ │ Report │
154
+ └─────────────┘
155
+ ```
156
+
157
+ ### Agents
158
+
159
+ diffray uses multiple specialized AI "agents" that each focus on one type of problem:
160
+
161
+ | Agent | What it finds |
162
+ |-------|---------------|
163
+ | `general` | Code quality, readability, simplicity issues |
164
+ | `bug-hunter` | Logic errors, null checks, edge cases |
165
+ | `security-scan` | Vulnerabilities, exposed secrets |
166
+ | `performance-check` | Memory leaks, slow code |
167
+ | `consistency-check` | Inconsistent patterns, naming conventions |
168
+
169
+ Each agent analyzes your code independently, then results are:
170
+ 1. **Deduplicated** - remove duplicates if multiple agents found the same issue
171
+ 2. **Validated** - AI double-checks each issue to filter out false alarms
172
+
173
+ Only verified issues are shown in the final report.
174
+
175
+ > **Want to understand the architecture?** See [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) for details on agents, executors, and the stage pipeline.
176
+
177
+ ## Configuration (Optional)
178
+
179
+ diffray works out of the box with sensible defaults. Create `.diffray.json` in your project to customize:
180
+
181
+ ### Example configuration
182
+
183
+ ```json
184
+ {
185
+ "excludePatterns": [
186
+ "**/*.test.ts",
187
+ "**/*.spec.ts",
188
+ "**/__tests__/**",
189
+ "dist/**"
190
+ ],
191
+ "concurrency": 6,
192
+ "executor": "claude-cli",
193
+ "agents": {
194
+ "performance-check": { "enabled": false },
195
+ "bug-hunter": { "model": "haiku", "timeout": 60 }
196
+ },
197
+ "rules": {
198
+ "code-security": { "enabled": false }
199
+ },
200
+ "executors": {
201
+ "claude-cli": {
202
+ "review": { "model": "sonnet", "timeout": 120, "concurrency": 6 },
203
+ "validation": { "model": "opus", "timeout": 180, "batchSize": 10 }
204
+ }
205
+ }
206
+ }
207
+ ```
118
208
 
119
- # Filter by severity (show only critical)
120
- diffray --severity=critical
209
+ ### Options reference
121
210
 
122
- # Filter by multiple severities (critical and high)
123
- diffray --severity=critical,high
211
+ | Option | Description |
212
+ |--------|-------------|
213
+ | `extends` | Load agents/rules from git repos (e.g., `["https://github.com/owner/repo#v1.0"]`) |
214
+ | `excludePatterns` | Glob patterns for files to skip |
215
+ | `concurrency` | Max parallel agents (1-10, default: **6**). Stage-specific settings override this. |
216
+ | `executor` | Which executor to use (`claude-cli`, `cursor-agent-cli`) |
217
+ | `agents.<name>` | Override agent settings (`enabled`, `model`, `timeout`) |
218
+ | `rules.<name>` | Override rule settings (`enabled`, `agent`) |
219
+ | `executors.<name>.<stage>` | Per-executor, per-stage settings (`model`, `timeout`, `concurrency`, `batchSize`) |
124
220
 
125
- # Combine options
126
- diffray --json --severity=critical
221
+ ### Extends
127
222
 
128
- # Output includes:
129
- # ~ README.md: +141 -5
130
- # ~ src/cli.ts: +107 -3
131
- # + src/config.test.ts: +52 -0
132
- # ...
223
+ Share agents and rules across projects by loading them from any git repository:
224
+
225
+ ```json
226
+ {
227
+ "extends": [
228
+ "https://github.com/diffray/diffray-rules"
229
+ ]
230
+ }
133
231
  ```
134
232
 
135
- ### Manage Agents
233
+ Supports any git URL:
234
+ - `https://github.com/owner/repo` — HTTPS, default branch
235
+ - `https://github.com/owner/repo#v1.0` — specific tag/branch
236
+ - `git@github.com:owner/repo.git` — SSH format
237
+
238
+ Then run `diffray extends install` to download. Agents/rules from extends have lower priority than local ones.
239
+
240
+ ### Config commands
136
241
 
137
242
  ```bash
138
- # List all agents
139
- diffray agents list
243
+ # Create config file
244
+ diffray config init
140
245
 
141
- # Show agent details
142
- diffray agents show bug-hunter
246
+ # Edit config in your editor
247
+ diffray config edit
248
+
249
+ # Show current config
250
+ diffray config show
143
251
  ```
144
252
 
145
- **Creating Custom Agents:**
253
+ ## Creating Custom Agents
254
+
255
+ You can create your own agents to check for anything you want! Agents are simple Markdown files.
256
+
257
+ ### Where to put agent files
146
258
 
147
- Agents are defined using Markdown files! See [Agent Configuration Guide](./docs/AGENTS.md) for details.
259
+ | Location | When to use |
260
+ |----------|-------------|
261
+ | `~/.diffray/agents/` | Your personal agents (work in all projects) |
262
+ | `.diffray/agents/` | Project-specific agents (share with team via git) |
148
263
 
149
- Create a new `.md` file in `~/.diffray/agents/` or `.diffray/agents/` with frontmatter and a system prompt.
264
+ ### Agent file format
150
265
 
151
- ### Manage Executors
266
+ Each agent is a `.md` file with two parts:
267
+
268
+ 1. **Header** (between `---` lines) - settings in YAML format
269
+ 2. **Body** - instructions for the AI (what to look for)
270
+
271
+ ### Step-by-step: Create your first agent
272
+
273
+ **Step 1.** Create the folder (if it doesn't exist):
152
274
 
153
275
  ```bash
154
- # List all executors
155
- diffray executors list
276
+ mkdir -p ~/.diffray/agents
277
+ ```
278
+
279
+ **Step 2.** Create a new file `~/.diffray/agents/my-rules.md`:
280
+
281
+ ```markdown
282
+ ---
283
+ name: my-rules
284
+ description: Checks for my team's coding standards
285
+ enabled: true
286
+ ---
287
+
288
+ You are a code reviewer checking for our team's coding standards.
156
289
 
157
- # Show executor details
158
- diffray executors show claude-cli
290
+ ## What to check:
159
291
 
160
- # Enable/disable executors
161
- diffray executors enable cerebras-api
162
- diffray executors disable claude-cli
292
+ 1. **No console.log** - All console.log statements should be removed before commit
293
+ 2. **Function comments** - All exported functions must have a description comment
294
+ 3. **Error handling** - All async functions must have try/catch blocks
295
+ 4. **Naming** - Variables should have meaningful names (no single letters except in loops)
296
+
297
+ ## How to report:
298
+
299
+ - Only report clear violations
300
+ - Be specific about what line and what's wrong
301
+ - Suggest how to fix it
302
+ ```
303
+
304
+ **Step 3.** Verify your agent is loaded:
305
+
306
+ ```bash
307
+ diffray agents
163
308
  ```
164
309
 
165
- ### Manage Rules
310
+ You should see `my-rules` in the list.
166
311
 
167
- Rules allow you to run different agents on different file types using glob patterns. Rules are defined in Markdown files.
312
+ **Step 4.** Run a review - your agent will now analyze your code!
168
313
 
169
314
  ```bash
170
- # List all rules
171
- diffray rules list
315
+ diffray
316
+ ```
172
317
 
173
- # Show rule details
174
- diffray rules show code-bugs
318
+ ### Header fields explained
175
319
 
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
320
+ ```yaml
321
+ ---
322
+ name: my-rules # Unique ID (lowercase, use dashes)
323
+ description: What it does # Short description
324
+ enabled: true # Set to false to disable temporarily
325
+ order: 10 # Lower = runs first (optional, default: 0)
326
+ ---
184
327
  ```
185
328
 
186
- **Creating Custom Rules:**
329
+ ### Example agents
187
330
 
188
- Create a new `.md` file in `~/.diffray/rules/` or `.diffray/rules/` with frontmatter:
331
+ #### React best practices checker
189
332
 
190
333
  ```markdown
191
334
  ---
192
- name: my-rule
193
- description: Description of what this rule does
194
- patterns:
195
- - "**/*.ts"
196
- - "**/*.tsx"
197
- agent: bug-hunter
335
+ name: react-checker
336
+ description: Checks React code for common mistakes
337
+ enabled: true
198
338
  ---
199
339
 
200
- Additional instructions for the agent when this rule matches.
340
+ You are a React expert reviewing code for common mistakes.
341
+
342
+ ## Check for:
343
+
344
+ 1. **Missing keys in lists** - All .map() rendering elements need unique key props
345
+ 2. **useEffect dependencies** - Missing dependencies in useEffect arrays
346
+ 3. **State mutations** - Direct state mutations instead of setState
347
+ 4. **Memory leaks** - Missing cleanup in useEffect (event listeners, subscriptions)
348
+
349
+ ## Ignore:
350
+ - Styling preferences
351
+ - Minor formatting issues
201
352
  ```
202
353
 
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}`
354
+ #### API security checker
207
355
 
208
- ### Configuration
356
+ ```markdown
357
+ ---
358
+ name: api-security
359
+ description: Checks API endpoints for security issues
360
+ enabled: true
361
+ ---
209
362
 
210
- diffray stores configuration in `~/.diffray/config.json`. This file stores executor settings and other preferences.
363
+ You are a security engineer reviewing API code.
211
364
 
212
- ```bash
213
- # Initialize configuration file
214
- diffray config init
365
+ ## Check for:
215
366
 
216
- # Show current configuration
217
- diffray config show
367
+ 1. **Missing authentication** - Endpoints without auth checks
368
+ 2. **SQL injection** - User input in SQL queries without parameterization
369
+ 3. **Missing rate limiting** - Public endpoints without rate limits
370
+ 4. **Exposed secrets** - API keys, passwords, tokens in code
218
371
 
219
- # Edit configuration in your $EDITOR
220
- diffray config edit
372
+ ## Report format:
373
+ - Severity: CRITICAL for exploitable issues, HIGH for potential issues
374
+ - Include the specific line and code snippet
375
+ - Explain the attack vector
376
+ - Provide a fix
377
+ ```
221
378
 
222
- # Reset to defaults
223
- diffray config reset
379
+ #### TypeScript strict checker
380
+
381
+ ```markdown
382
+ ---
383
+ name: typescript-strict
384
+ description: Enforces strict TypeScript practices
385
+ enabled: true
386
+ ---
387
+
388
+ You are a TypeScript expert checking for type safety.
389
+
390
+ ## Check for:
391
+
392
+ 1. **any type** - Usage of 'any' type (should be specific type or 'unknown')
393
+ 2. **Type assertions** - Unnecessary 'as' casts that could hide errors
394
+ 3. **Missing null checks** - Accessing properties that could be null/undefined
395
+ 4. **Implicit any** - Function parameters without type annotations
396
+
397
+ ## Ignore:
398
+ - Third-party library types
399
+ - Test files
224
400
  ```
225
401
 
226
- #### Configuration Structure
402
+ ### Tips for writing good agents
227
403
 
228
- The configuration file has the following structure:
404
+ 1. **Be specific** - "Check for console.log" is better than "check for debug code"
405
+ 2. **Give examples** - Show what bad code looks like
406
+ 3. **Set priorities** - Tell the AI what's important vs minor
407
+ 4. **Define what to ignore** - Reduce false positives
229
408
 
230
- ```json
409
+ ### Managing agents
410
+
411
+ ```bash
412
+ # List all agents (shows name, description, enabled status)
413
+ diffray agents
414
+
415
+ # Show full details of an agent
416
+ diffray agents bug-hunter
417
+
418
+ # Disable an agent via config (without deleting the file)
419
+ # Add to .diffray.json:
231
420
  {
232
- "excludePatterns": ["*.lock", "*.min.js", "dist/*", "node_modules/**"],
233
- "output": {
234
- "colorize": true,
235
- "verbose": false,
236
- "format": "terminal"
237
- },
238
- "executors": [...],
239
- "stages": [...]
421
+ "agents": {
422
+ "my-rules": { "enabled": false }
423
+ }
240
424
  }
241
425
  ```
242
426
 
243
- **Key Sections:**
427
+ ### Troubleshooting
244
428
 
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
429
+ **Agent not showing up?**
430
+ - Check file has `.md` extension
431
+ - Check file is in correct folder (`~/.diffray/agents/` or `.diffray/agents/`)
432
+ - Check YAML header syntax (must be between `---` lines)
251
433
 
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/`
434
+ **Agent not finding issues?**
435
+ - Make instructions more specific
436
+ - Add examples of what to look for
437
+ - Check `enabled: true` in header
255
438
 
256
- ### Executors Configuration
439
+ ## Creating Custom Rules
257
440
 
258
- Executors define **how** to run Agents. diffray supports multiple executor types:
441
+ Rules connect agents to files. They tell diffray: "Run this agent on these files".
259
442
 
260
- - **CLI Executors** - Run CLI tools like `claude`, `auggie`, etc.
261
- - **LLM API Executors** - Call LLM APIs directly (Claude, GPT, etc.)
443
+ ### What are rules?
262
444
 
263
- Executors are configured in `~/.diffray/config.json`.
445
+ By default, diffray runs ALL agents on ALL changed files. But with rules you can:
264
446
 
265
- #### Executor Configuration
447
+ - Run `security-scan` agent **only** on `*.ts` files
448
+ - Run `python-checker` agent **only** on `*.py` files
449
+ - Add extra instructions for specific file types
266
450
 
267
- Executors can be configured in `~/.diffray/config.json`:
451
+ ### Where to put rule files
268
452
 
269
- ```json
270
- {
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
- ]
286
- }
453
+ | Location | When to use |
454
+ |----------|-------------|
455
+ | `~/.diffray/rules/` | Your personal rules (work in all projects) |
456
+ | `.diffray/rules/` | Project-specific rules (share with team via git) |
457
+
458
+ ### Rule file format
459
+
460
+ Rules are also Markdown files with a header:
461
+
462
+ ```markdown
463
+ ---
464
+ name: frontend-bugs
465
+ description: Bug detection for React frontend
466
+ patterns:
467
+ - "src/components/**/*.tsx"
468
+ - "src/hooks/**/*.ts"
469
+ agent: bug-hunter
470
+ ---
471
+
472
+ Extra instructions for this rule (optional).
473
+
474
+ Focus on React-specific issues like:
475
+ - Missing useCallback/useMemo
476
+ - Incorrect dependency arrays
477
+ ```
478
+
479
+ ### Step-by-step: Create your first rule
480
+
481
+ **Step 1.** Create the folder:
482
+
483
+ ```bash
484
+ mkdir -p ~/.diffray/rules
485
+ ```
486
+
487
+ **Step 2.** Create `~/.diffray/rules/python-security.md`:
488
+
489
+ ```markdown
490
+ ---
491
+ name: python-security
492
+ description: Security checks for Python files
493
+ patterns:
494
+ - "**/*.py"
495
+ agent: security-scan
496
+ ---
497
+
498
+ Focus on Python-specific security issues:
499
+
500
+ 1. **eval() and exec()** - Dynamic code execution
501
+ 2. **pickle** - Insecure deserialization
502
+ 3. **subprocess** - Command injection via shell=True
503
+ 4. **SQL** - String formatting in SQL queries
504
+ 5. **YAML** - yaml.load() without safe_load
505
+ ```
506
+
507
+ **Step 3.** Verify your rule is loaded:
508
+
509
+ ```bash
510
+ diffray rules
511
+ ```
512
+
513
+ **Step 4.** Test which files match your rule:
514
+
515
+ ```bash
516
+ diffray rules python-security --test src/
287
517
  ```
288
518
 
289
- #### Executor Options
519
+ ### Header fields explained
290
520
 
291
- **CLI Executors (claude-cli):**
292
- - `enabled` - Enable/disable executor
293
- - `model` - Model to use (default: `sonnet`)
294
- - `timeout` - Timeout in seconds (default: 120)
521
+ ```yaml
522
+ ---
523
+ name: python-security # Unique ID (lowercase, use dashes)
524
+ description: What it does # Short description
525
+ patterns: # Which files to match (glob patterns)
526
+ - "**/*.py" # All Python files
527
+ - "scripts/*.sh" # Shell scripts in scripts/ folder
528
+ agent: security-scan # Which agent to run on matched files
529
+ ---
530
+ ```
295
531
 
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)
532
+ ### Understanding patterns (glob syntax)
301
533
 
302
- #### Linking Agents to Executors
534
+ Patterns use "glob" syntax to match files:
303
535
 
304
- Agents reference executors via the `executor` field in their Markdown configuration:
536
+ | Pattern | What it matches |
537
+ |---------|-----------------|
538
+ | `*.ts` | All `.ts` files in root folder only |
539
+ | `**/*.ts` | All `.ts` files in any folder |
540
+ | `src/**/*.ts` | All `.ts` files inside `src/` folder |
541
+ | `src/*.ts` | Only `.ts` files directly in `src/` (not subfolders) |
542
+ | `**/*.{ts,tsx}` | All `.ts` and `.tsx` files |
543
+ | `!**/*.test.ts` | Exclude test files (prefix with `!`) |
544
+
545
+ ### Example rules
546
+
547
+ #### Backend API security
305
548
 
306
549
  ```markdown
307
550
  ---
308
- name: bug-hunter
309
- executor: claude-cli
551
+ name: api-security
552
+ description: Security review for API endpoints
553
+ patterns:
554
+ - "src/api/**/*.ts"
555
+ - "src/routes/**/*.ts"
556
+ - "src/controllers/**/*.ts"
557
+ agent: security-scan
558
+ ---
559
+
560
+ Focus on API security:
561
+
562
+ 1. Check authentication on all endpoints
563
+ 2. Validate all user input
564
+ 3. Check for SQL/NoSQL injection
565
+ 4. Verify rate limiting
566
+ 5. Check CORS configuration
567
+ ```
568
+
569
+ #### React components quality
570
+
571
+ ```markdown
310
572
  ---
573
+ name: react-quality
574
+ description: Quality checks for React components
575
+ patterns:
576
+ - "src/components/**/*.tsx"
577
+ - "src/pages/**/*.tsx"
578
+ agent: bug-hunter
579
+ ---
580
+
581
+ Focus on React best practices:
582
+
583
+ 1. Missing key props in lists
584
+ 2. useEffect dependency arrays
585
+ 3. Memory leaks (missing cleanup)
586
+ 4. Prop types validation
587
+ 5. Conditional rendering bugs
311
588
  ```
312
589
 
313
- ## Agent Configuration
590
+ #### Config files security
314
591
 
315
- Agents are configured using **Markdown files** in `src/defaults/agents/`. See the [Agent Configuration Guide](./docs/AGENTS.md) for complete documentation.
592
+ ```markdown
593
+ ---
594
+ name: config-security
595
+ description: Check config files for exposed secrets
596
+ patterns:
597
+ - "**/*.json"
598
+ - "**/*.yaml"
599
+ - "**/*.yml"
600
+ - "**/*.env.example"
601
+ agent: security-scan
602
+ ---
603
+
604
+ Check for:
316
605
 
317
- ### Agent Markdown Format
606
+ 1. Hardcoded API keys or tokens
607
+ 2. Database credentials
608
+ 3. Private keys
609
+ 4. Sensitive URLs
610
+ ```
318
611
 
319
- Each agent is defined in a `.md` file with frontmatter metadata:
612
+ #### Documentation checker
613
+
614
+ ```markdown
615
+ ---
616
+ name: docs-quality
617
+ description: Check documentation for issues
618
+ patterns:
619
+ - "**/*.md"
620
+ - "docs/**/*"
621
+ agent: general
622
+ ---
623
+
624
+ Check documentation for:
625
+
626
+ 1. Broken links
627
+ 2. Outdated code examples
628
+ 3. Missing sections
629
+ 4. Typos in commands
630
+ ```
631
+
632
+ ### Default rules (built-in)
633
+
634
+ diffray comes with these rules out of the box:
635
+
636
+ | Rule | Files | Agent |
637
+ |------|-------|-------|
638
+ | `code-general` | `*.ts, *.js, *.py, *.go, *.rs, *.java, *.rb, *.php, ...` | `general` |
639
+ | `code-bugs` | Same as above | `bug-hunter` |
640
+ | `code-security` | Same as above | `security-scan` |
641
+ | `code-performance` | Same as above | `performance-check` |
642
+ | `code-consistency` | Same as above + `*.md, *.json, *.yaml` | `consistency-check` |
643
+ | `config-security` | `*.json, *.yaml, *.yml, *.toml` | `security-scan` |
644
+
645
+ ### Managing rules
646
+
647
+ ```bash
648
+ # List all rules
649
+ diffray rules
650
+
651
+ # Show rule details
652
+ diffray rules code-bugs
653
+
654
+ # Test which files a rule matches
655
+ diffray rules code-bugs --test src/
656
+
657
+ # Disable a rule via config
658
+ # Add to .diffray.json:
659
+ {
660
+ "rules": {
661
+ "code-performance": { "enabled": false }
662
+ }
663
+ }
664
+ ```
665
+
666
+ ### Rules vs Agents: What's the difference?
667
+
668
+ | | Agent | Rule |
669
+ |---|-------|------|
670
+ | **What** | The AI reviewer (what to check) | The file filter (where to check) |
671
+ | **Contains** | Instructions for AI | File patterns + which agent to use |
672
+ | **Example** | "Check for SQL injection" | "Run security-scan on *.py files" |
673
+
674
+ **Think of it this way:**
675
+ - **Agent** = The inspector (knows what problems to look for)
676
+ - **Rule** = The assignment (tells inspector which rooms to check)
677
+
678
+ ### Troubleshooting
679
+
680
+ **Rule not matching files?**
681
+ - Check pattern syntax (use `**/*.ts` not `*.ts` for recursive)
682
+ - Test with `diffray rules your-rule --test path/`
683
+ - Remember patterns are relative to project root
684
+
685
+ **Agent not running on expected files?**
686
+ - Make sure rule's `agent` field matches an existing agent name
687
+ - Check that both rule and agent have `enabled: true`
688
+
689
+ ## Overriding Agents and Rules
690
+
691
+ Besides config file overrides (see [Configuration](#configuration-optional)), you can completely replace built-in agents/rules by creating files with the same name.
692
+
693
+ **Priority order (highest to lowest):**
694
+ 1. `.diffray/agents/` or `.diffray/rules/` (project folder)
695
+ 2. `~/.diffray/agents/` or `~/.diffray/rules/` (home folder)
696
+ 3. Built-in defaults
697
+
698
+ **Example:** To replace the built-in `bug-hunter` agent:
699
+
700
+ ```bash
701
+ mkdir -p .diffray/agents
702
+ ```
703
+
704
+ Create `.diffray/agents/bug-hunter.md`:
320
705
 
321
706
  ```markdown
322
707
  ---
323
708
  name: bug-hunter
324
- description: Detects bugs, logic errors and runtime issues
709
+ description: My custom bug hunter
325
710
  enabled: true
326
- executor: claude-cli
327
711
  ---
328
712
 
329
- You are a code reviewer analyzing changes for:
713
+ Your completely custom instructions here...
714
+ ```
715
+
716
+ ## FAQ
330
717
 
331
- ### Logic Errors
332
- - Identify bugs and edge cases
333
- - Check error handling
718
+ ### Why is it slow?
334
719
 
335
- ### Code Quality
336
- - Assess readability
337
- - Check naming conventions
720
+ diffray uses Claude AI which takes time to analyze code properly. Typical review takes 10-30 seconds. For faster (but less accurate) reviews, use:
721
+
722
+ ```bash
723
+ diffray --skip-validation
338
724
  ```
339
725
 
340
- The system automatically loads all `.md` files from `~/.diffray/agents/`, `.diffray/agents/`, and `src/defaults/agents/`.
726
+ ### Why didn't it find an obvious bug?
727
+
728
+ 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).
729
+
730
+ ### Can I use it in CI/CD?
341
731
 
342
- ## Example Output
732
+ Yes! Use `--json` flag for machine-readable output:
343
733
 
734
+ ```bash
735
+ diffray --json --severity critical,high
344
736
  ```
345
- ⚡ diffray - AI Code Review
346
737
 
347
- Analyzing changes...
738
+ Exit code is non-zero if issues are found.
739
+
740
+ **GitHub Actions example:**
348
741
 
349
- Summary: 2 modified, 1 added
742
+ ```yaml
743
+ name: Code Review
744
+ on: [pull_request]
350
745
 
351
- ================================================================================
746
+ jobs:
747
+ review:
748
+ runs-on: ubuntu-latest
749
+ steps:
750
+ - uses: actions/checkout@v4
751
+ with:
752
+ fetch-depth: 0
352
753
 
353
- src/index.ts (modified)
754
+ - uses: actions/setup-node@v4
755
+ with:
756
+ node-version: '20'
354
757
 
355
- + export function greet(name: string): string {
356
- + return `Hello, ${name}!`;
357
- + }
758
+ - run: npm install -g diffray @anthropic-ai/claude-code
358
759
 
359
- --------------------------------------------------------------------------------
760
+ - run: claude auth login --api-key ${{ secrets.ANTHROPIC_API_KEY }}
360
761
 
361
- Reviewed 3 file(s)
762
+ - run: diffray --base origin/${{ github.base_ref }} --json --severity critical,high
362
763
  ```
363
764
 
765
+ ### How much does it cost?
766
+
767
+ 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.
768
+
769
+ ## Get Results in Your PRs
770
+
771
+ Want automated reviews directly in GitHub Pull Requests?
772
+
773
+ **Sign up at [diffray.ai](https://diffray.ai)** - connect your repo and get AI review comments on every PR automatically.
774
+
364
775
  ## Development
365
776
 
366
777
  ```bash
367
- # Run in development mode
368
- bun run dev
778
+ # Clone the repo
779
+ git clone https://github.com/diffray/diffray.git
780
+ cd diffray
369
781
 
370
- # Build standalone binary
371
- bun run build
782
+ # Install dependencies
783
+ npm install
372
784
 
373
- # Run tests
374
- bun test
375
- ```
785
+ # Run in dev mode
786
+ npm run dev
376
787
 
377
- ## Project Structure
788
+ # Run tests
789
+ npm test
378
790
 
791
+ # Build
792
+ npm run build
379
793
  ```
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
794
 
398
- - [Bun](https://bun.sh) - Fast JavaScript runtime
399
- - TypeScript - Type safety
795
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed development guidelines.
400
796
 
401
797
  ## License
402
798
 
403
799
  MIT
800
+
801
+ ---
802
+
803
+ **[Changelog](CHANGELOG.md)** · **[Contributing](CONTRIBUTING.md)** · **[Architecture](docs/ARCHITECTURE.md)**