diffray 0.2.0 → 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 (3) hide show
  1. package/README.md +73 -289
  2. package/dist/diffray.cjs +208 -201
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,85 +1,37 @@
1
- <p align="center">
2
- <img src="logo.svg" alt="diffray" width="200">
3
- </p>
4
-
5
- <h1 align="center">diffray</h1>
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.
6
14
 
7
15
  <p align="center">
8
- <strong>AI code reviewer that finds real bugs in your code</strong>
16
+ <img src="/docs/diffray.png" alt="diffray in action" width="800">
9
17
  </p>
10
18
 
19
+ ---
20
+
11
21
  ## Table of Contents
12
22
 
13
- **Getting Started**
14
- - [What is diffray?](#what-is-diffray)
15
- - [Quick Start](#quick-start) · [Quick Reference](#quick-reference)
23
+ - [Quick Start](#quick-start)
16
24
  - [Prerequisites](#prerequisites)
17
- - [Common Commands](#common-commands)
18
25
  - [How It Works](#how-it-works)
19
-
20
- **Customization**
21
26
  - [Configuration](#configuration-optional)
22
27
  - [Creating Custom Agents](#creating-custom-agents)
23
28
  - [Creating Custom Rules](#creating-custom-rules)
24
29
  - [Overriding Agents and Rules](#overriding-agents-and-rules)
25
-
26
- **Reference**
27
30
  - [FAQ](#faq)
28
31
  - [Development](#development)
29
- - [Contributing](CONTRIBUTING.md)
30
- - [Changelog](CHANGELOG.md)
31
32
 
32
33
  ---
33
34
 
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
-
42
- ```
43
- You write code → diffray analyzes it → You get a list of issues to fix
44
- ```
45
-
46
- ### What it finds:
47
-
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
51
-
52
- ### Example output:
53
-
54
- ```
55
- ⚡ diffray - AI Code Review
56
-
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
- ```
82
-
83
35
  ## Quick Start
84
36
 
85
37
  ### 1. Install diffray
@@ -104,17 +56,34 @@ diffray --base main
104
56
 
105
57
  That's it! diffray will analyze your changes and show any issues found.
106
58
 
107
- ### Quick Reference
59
+ ### Common Commands
60
+
61
+ ```bash
62
+ # Review uncommitted changes, or last commit if clean
63
+ diffray
64
+
65
+ # Review changes compared to main branch
66
+ diffray --base main
67
+
68
+ # Review last 3 commits
69
+ diffray --base HEAD~3
70
+
71
+ # Show only critical and high severity issues
72
+ diffray --severity critical,high
73
+
74
+ # Run only specific agent
75
+ diffray --agent bug-hunter
108
76
 
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 |
77
+ # Output as JSON (for CI/CD pipelines)
78
+ diffray --json
79
+
80
+ # Show detailed progress
81
+ diffray --stream
82
+
83
+ # List available agents and rules
84
+ diffray agents
85
+ diffray rules
86
+ ```
118
87
 
119
88
  ## Prerequisites
120
89
 
@@ -142,7 +111,7 @@ If you use Cursor IDE, you can use its agent CLI instead:
142
111
  curl https://cursor.com/install -fsS | bash
143
112
 
144
113
  # Authorize (opens browser)
145
- cursor-agent auth
114
+ cursor-agent
146
115
  ```
147
116
 
148
117
  Then switch diffray to use it:
@@ -156,16 +125,6 @@ diffray config init
156
125
  diffray review --executor cursor-agent-cli
157
126
  ```
158
127
 
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
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.
170
129
 
171
130
  **Tips to reduce costs:**
@@ -173,28 +132,6 @@ Costs depend on your AI provider's pricing. Claude Code uses your Anthropic acco
173
132
  - Use `--agent` flag to run only specific agents
174
133
  - Use `--skip-validation` to skip the validation stage (faster but more false positives)
175
134
 
176
- ## Common Commands
177
-
178
- ```bash
179
- # Review uncommitted changes, or last commit if clean (most common)
180
- diffray
181
-
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)
192
- diffray --json
193
-
194
- # Show detailed progress
195
- diffray --stream
196
- ```
197
-
198
135
  ## How It Works
199
136
 
200
137
  ### Pipeline
@@ -239,35 +176,9 @@ Only verified issues are shown in the final report.
239
176
 
240
177
  ## Configuration (Optional)
241
178
 
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
179
+ diffray works out of the box with sensible defaults. Create `.diffray.json` in your project to customize:
257
180
 
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:
181
+ ### Example configuration
271
182
 
272
183
  ```json
273
184
  {
@@ -275,86 +186,56 @@ Here's a practical `.diffray.json` for a TypeScript/React project:
275
186
  "**/*.test.ts",
276
187
  "**/*.spec.ts",
277
188
  "**/__tests__/**",
278
- "dist/**",
279
- "node_modules/**"
189
+ "dist/**"
280
190
  ],
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,
191
+ "concurrency": 6,
295
192
  "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
193
  "agents": {
303
- "security-scan": { "enabled": false },
194
+ "performance-check": { "enabled": false },
304
195
  "bug-hunter": { "model": "haiku", "timeout": 60 }
305
196
  },
306
197
  "rules": {
307
198
  "code-security": { "enabled": false }
308
199
  },
309
- "output": {
310
- "colorize": true,
311
- "verbose": false,
312
- "format": "terminal"
200
+ "executors": {
201
+ "claude-cli": {
202
+ "review": { "model": "sonnet", "timeout": 120, "concurrency": 6 },
203
+ "validation": { "model": "opus", "timeout": 180, "batchSize": 10 }
204
+ }
313
205
  }
314
206
  }
315
207
  ```
316
208
 
209
+ ### Options reference
210
+
317
211
  | Option | Description |
318
212
  |--------|-------------|
213
+ | `extends` | Load agents/rules from git repos (e.g., `["https://github.com/owner/repo#v1.0"]`) |
319
214
  | `excludePatterns` | Glob patterns for files to skip |
320
- | `concurrency` | Global max parallel agents (1-10, default: **6**) |
215
+ | `concurrency` | Max parallel agents (1-10, default: **6**). Stage-specific settings override this. |
321
216
  | `executor` | Which executor to use (`claude-cli`, `cursor-agent-cli`) |
322
- | `executors.<name>.<stage>` | Per-executor, per-stage settings |
323
217
  | `agents.<name>` | Override agent settings (`enabled`, `model`, `timeout`) |
324
218
  | `rules.<name>` | Override rule settings (`enabled`, `agent`) |
219
+ | `executors.<name>.<stage>` | Per-executor, per-stage settings (`model`, `timeout`, `concurrency`, `batchSize`) |
325
220
 
326
- ### Concurrency settings
221
+ ### Extends
327
222
 
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:**
223
+ Share agents and rules across projects by loading them from any git repository:
333
224
 
334
225
  ```json
335
226
  {
336
- "concurrency": 6,
337
- "executors": {
338
- "claude-cli": {
339
- "review": { "concurrency": 6 },
340
- "validation": { "concurrency": 3 }
341
- }
342
- }
227
+ "extends": [
228
+ "https://github.com/diffray/diffray-rules"
229
+ ]
343
230
  }
344
231
  ```
345
232
 
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
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
353
237
 
354
- **Recommendations:**
355
- - **Fast machine + good internet:** `6` (default)
356
- - **Rate limited API:** `2-3`
357
- - **Debugging:** `1` (sequential, easier to read logs)
238
+ Then run `diffray extends install` to download. Agents/rules from extends have lower priority than local ones.
358
239
 
359
240
  ### Config commands
360
241
 
@@ -807,61 +688,20 @@ diffray rules code-bugs --test src/
807
688
 
808
689
  ## Overriding Agents and Rules
809
690
 
810
- You can override built-in agents and rules without editing their original files. This is useful when you want to:
811
-
812
- - Disable a built-in agent or rule
813
- - Change settings for a specific project
814
- - Override agent's model or timeout
815
-
816
- ### Override via config file
817
-
818
- Create `.diffray.json` in your project root:
819
-
820
- ```json
821
- {
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
- }
830
- }
831
- ```
832
-
833
- ### Agent overrides
834
-
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 }` |
840
-
841
- ### Rule overrides
842
-
843
- | Field | What it does | Example |
844
- |-------|--------------|---------|
845
- | `enabled` | Turn rule on/off | `{ "enabled": false }` |
846
- | `agent` | Use different agent | `{ "agent": "my-agent" }` |
847
-
848
- ### Override by creating your own file
849
-
850
- If a file with the same `name` exists in a higher-priority folder, it overrides the lower one.
691
+ Besides config file overrides (see [Configuration](#configuration-optional)), you can completely replace built-in agents/rules by creating files with the same name.
851
692
 
852
693
  **Priority order (highest to lowest):**
853
694
  1. `.diffray/agents/` or `.diffray/rules/` (project folder)
854
695
  2. `~/.diffray/agents/` or `~/.diffray/rules/` (home folder)
855
696
  3. Built-in defaults
856
697
 
857
- **Example:** To override the built-in `bug-hunter` agent, create:
698
+ **Example:** To replace the built-in `bug-hunter` agent:
858
699
 
859
700
  ```bash
860
- # Create project-specific override
861
701
  mkdir -p .diffray/agents
862
702
  ```
863
703
 
864
- Then create `.diffray/agents/bug-hunter.md`:
704
+ Create `.diffray/agents/bug-hunter.md`:
865
705
 
866
706
  ```markdown
867
707
  ---
@@ -873,62 +713,6 @@ enabled: true
873
713
  Your completely custom instructions here...
874
714
  ```
875
715
 
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
- ```
920
-
921
- #### Increase timeout for large files
922
-
923
- ```json
924
- {
925
- "agents": {
926
- "bug-hunter": { "timeout": 300 },
927
- "security-scan": { "timeout": 300 }
928
- }
929
- }
930
- ```
931
-
932
716
  ## FAQ
933
717
 
934
718
  ### Why is it slow?