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.
- package/README.md +659 -259
- package/dist/defaults/agents/api-design.md +31 -0
- package/dist/defaults/agents/bug-hunter.md +0 -1
- package/dist/defaults/agents/consistency-check.md +27 -0
- package/dist/defaults/agents/data-privacy.md +30 -0
- package/dist/defaults/agents/database.md +30 -0
- package/dist/defaults/agents/general.md +0 -1
- package/dist/defaults/agents/i18n.md +29 -0
- package/dist/defaults/agents/observability.md +30 -0
- package/dist/defaults/agents/performance-check.md +0 -1
- package/dist/defaults/agents/security-scan.md +0 -1
- package/dist/defaults/agents/validation.md +0 -1
- package/dist/defaults/prompts/INDEX.md +178 -0
- package/dist/defaults/prompts/README.md +173 -0
- package/dist/defaults/prompts/SUMMARY.md +276 -0
- package/dist/defaults/prompts/USAGE.md +277 -0
- package/dist/defaults/prompts/api-design.md +119 -0
- package/dist/defaults/prompts/data-privacy.md +144 -0
- package/dist/defaults/prompts/database.md +105 -0
- package/dist/defaults/prompts/i18n.md +89 -0
- package/dist/defaults/prompts/observability.md +142 -0
- package/dist/defaults/rules/code-consistency.md +74 -0
- package/dist/diffray.cjs +354 -0
- package/package.json +29 -13
- package/src/defaults/agents/bug-hunter.md +0 -1
- package/src/defaults/agents/consistency-check.md +27 -0
- package/src/defaults/agents/general.md +0 -1
- package/src/defaults/agents/performance-check.md +0 -1
- package/src/defaults/agents/security-scan.md +0 -1
- package/src/defaults/agents/validation.md +0 -1
- package/src/defaults/rules/code-consistency.md +74 -0
- 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="
|
|
16
|
+
<img src="/docs/diffray.png" alt="diffray in action" width="800">
|
|
3
17
|
</p>
|
|
4
18
|
|
|
5
|
-
|
|
19
|
+
---
|
|
6
20
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
57
|
+
That's it! diffray will analyze your changes and show any issues found.
|
|
16
58
|
|
|
17
|
-
|
|
59
|
+
### Common Commands
|
|
18
60
|
|
|
19
|
-
|
|
61
|
+
```bash
|
|
62
|
+
# Review uncommitted changes, or last commit if clean
|
|
63
|
+
diffray
|
|
20
64
|
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
68
|
+
# Review last 3 commits
|
|
69
|
+
diffray --base HEAD~3
|
|
27
70
|
|
|
28
|
-
|
|
71
|
+
# Show only critical and high severity issues
|
|
72
|
+
diffray --severity critical,high
|
|
29
73
|
|
|
30
|
-
|
|
31
|
-
|
|
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
|
-
|
|
77
|
+
# Output as JSON (for CI/CD pipelines)
|
|
78
|
+
diffray --json
|
|
37
79
|
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
83
|
+
# List available agents and rules
|
|
84
|
+
diffray agents
|
|
85
|
+
diffray rules
|
|
86
|
+
```
|
|
44
87
|
|
|
45
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
95
|
+
Claude Code is an official Anthropic CLI tool with agentic capabilities.
|
|
62
96
|
|
|
63
|
-
|
|
97
|
+
```bash
|
|
98
|
+
# Install
|
|
99
|
+
npm install -g @anthropic-ai/claude-code
|
|
64
100
|
|
|
65
|
-
|
|
101
|
+
# Authorize (opens browser for OAuth)
|
|
102
|
+
claude auth login
|
|
103
|
+
```
|
|
66
104
|
|
|
67
|
-
|
|
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
|
-
|
|
107
|
+
If you use Cursor IDE, you can use its agent CLI instead:
|
|
74
108
|
|
|
75
|
-
|
|
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
|
-
#
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
bun install
|
|
120
|
+
# Via config
|
|
121
|
+
diffray config init
|
|
122
|
+
# Edit .diffray.json and add: "executor": "cursor-agent-cli"
|
|
82
123
|
|
|
83
|
-
#
|
|
84
|
-
|
|
124
|
+
# Or per-run
|
|
125
|
+
diffray review --executor cursor-agent-cli
|
|
85
126
|
```
|
|
86
127
|
|
|
87
|
-
|
|
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
|
-
|
|
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
|
-
|
|
135
|
+
## How It Works
|
|
92
136
|
|
|
93
|
-
|
|
94
|
-
# Run code review pipeline
|
|
95
|
-
diffray
|
|
137
|
+
### Pipeline
|
|
96
138
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
diffray
|
|
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
|
-
|
|
120
|
-
diffray --severity=critical
|
|
209
|
+
### Options reference
|
|
121
210
|
|
|
122
|
-
|
|
123
|
-
|
|
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
|
-
|
|
126
|
-
diffray --json --severity=critical
|
|
221
|
+
### Extends
|
|
127
222
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
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
|
-
#
|
|
139
|
-
diffray
|
|
243
|
+
# Create config file
|
|
244
|
+
diffray config init
|
|
140
245
|
|
|
141
|
-
#
|
|
142
|
-
diffray
|
|
246
|
+
# Edit config in your editor
|
|
247
|
+
diffray config edit
|
|
248
|
+
|
|
249
|
+
# Show current config
|
|
250
|
+
diffray config show
|
|
143
251
|
```
|
|
144
252
|
|
|
145
|
-
|
|
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
|
-
|
|
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
|
-
|
|
264
|
+
### Agent file format
|
|
150
265
|
|
|
151
|
-
|
|
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
|
-
|
|
155
|
-
|
|
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
|
-
|
|
158
|
-
diffray executors show claude-cli
|
|
290
|
+
## What to check:
|
|
159
291
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
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
|
-
|
|
310
|
+
You should see `my-rules` in the list.
|
|
166
311
|
|
|
167
|
-
|
|
312
|
+
**Step 4.** Run a review - your agent will now analyze your code!
|
|
168
313
|
|
|
169
314
|
```bash
|
|
170
|
-
|
|
171
|
-
|
|
315
|
+
diffray
|
|
316
|
+
```
|
|
172
317
|
|
|
173
|
-
|
|
174
|
-
diffray rules show code-bugs
|
|
318
|
+
### Header fields explained
|
|
175
319
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
#
|
|
179
|
-
|
|
180
|
-
#
|
|
181
|
-
#
|
|
182
|
-
|
|
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
|
-
|
|
329
|
+
### Example agents
|
|
187
330
|
|
|
188
|
-
|
|
331
|
+
#### React best practices checker
|
|
189
332
|
|
|
190
333
|
```markdown
|
|
191
334
|
---
|
|
192
|
-
name:
|
|
193
|
-
description:
|
|
194
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
356
|
+
```markdown
|
|
357
|
+
---
|
|
358
|
+
name: api-security
|
|
359
|
+
description: Checks API endpoints for security issues
|
|
360
|
+
enabled: true
|
|
361
|
+
---
|
|
209
362
|
|
|
210
|
-
|
|
363
|
+
You are a security engineer reviewing API code.
|
|
211
364
|
|
|
212
|
-
|
|
213
|
-
# Initialize configuration file
|
|
214
|
-
diffray config init
|
|
365
|
+
## Check for:
|
|
215
366
|
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
220
|
-
|
|
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
|
-
|
|
223
|
-
|
|
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
|
-
|
|
402
|
+
### Tips for writing good agents
|
|
227
403
|
|
|
228
|
-
|
|
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
|
-
|
|
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
|
-
"
|
|
233
|
-
|
|
234
|
-
|
|
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
|
-
|
|
427
|
+
### Troubleshooting
|
|
244
428
|
|
|
245
|
-
|
|
246
|
-
-
|
|
247
|
-
-
|
|
248
|
-
-
|
|
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
|
-
**
|
|
253
|
-
-
|
|
254
|
-
-
|
|
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
|
-
|
|
439
|
+
## Creating Custom Rules
|
|
257
440
|
|
|
258
|
-
|
|
441
|
+
Rules connect agents to files. They tell diffray: "Run this agent on these files".
|
|
259
442
|
|
|
260
|
-
|
|
261
|
-
- **LLM API Executors** - Call LLM APIs directly (Claude, GPT, etc.)
|
|
443
|
+
### What are rules?
|
|
262
444
|
|
|
263
|
-
|
|
445
|
+
By default, diffray runs ALL agents on ALL changed files. But with rules you can:
|
|
264
446
|
|
|
265
|
-
|
|
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
|
-
|
|
451
|
+
### Where to put rule files
|
|
268
452
|
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
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
|
-
|
|
519
|
+
### Header fields explained
|
|
290
520
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
-
|
|
294
|
-
|
|
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
|
-
|
|
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
|
-
|
|
534
|
+
Patterns use "glob" syntax to match files:
|
|
303
535
|
|
|
304
|
-
|
|
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:
|
|
309
|
-
|
|
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
|
-
|
|
590
|
+
#### Config files security
|
|
314
591
|
|
|
315
|
-
|
|
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
|
-
|
|
606
|
+
1. Hardcoded API keys or tokens
|
|
607
|
+
2. Database credentials
|
|
608
|
+
3. Private keys
|
|
609
|
+
4. Sensitive URLs
|
|
610
|
+
```
|
|
318
611
|
|
|
319
|
-
|
|
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:
|
|
709
|
+
description: My custom bug hunter
|
|
325
710
|
enabled: true
|
|
326
|
-
executor: claude-cli
|
|
327
711
|
---
|
|
328
712
|
|
|
329
|
-
|
|
713
|
+
Your completely custom instructions here...
|
|
714
|
+
```
|
|
715
|
+
|
|
716
|
+
## FAQ
|
|
330
717
|
|
|
331
|
-
###
|
|
332
|
-
- Identify bugs and edge cases
|
|
333
|
-
- Check error handling
|
|
718
|
+
### Why is it slow?
|
|
334
719
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
738
|
+
Exit code is non-zero if issues are found.
|
|
739
|
+
|
|
740
|
+
**GitHub Actions example:**
|
|
348
741
|
|
|
349
|
-
|
|
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
|
-
|
|
754
|
+
- uses: actions/setup-node@v4
|
|
755
|
+
with:
|
|
756
|
+
node-version: '20'
|
|
354
757
|
|
|
355
|
-
|
|
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
|
-
|
|
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
|
-
#
|
|
368
|
-
|
|
778
|
+
# Clone the repo
|
|
779
|
+
git clone https://github.com/diffray/diffray.git
|
|
780
|
+
cd diffray
|
|
369
781
|
|
|
370
|
-
#
|
|
371
|
-
|
|
782
|
+
# Install dependencies
|
|
783
|
+
npm install
|
|
372
784
|
|
|
373
|
-
# Run
|
|
374
|
-
|
|
375
|
-
```
|
|
785
|
+
# Run in dev mode
|
|
786
|
+
npm run dev
|
|
376
787
|
|
|
377
|
-
|
|
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
|
-
|
|
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)**
|