Skip to content

Commit e2cc2e0

Browse files
committed
chore: initial commit
0 parents  commit e2cc2e0

File tree

16 files changed

+3664
-0
lines changed

16 files changed

+3664
-0
lines changed

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Platform tokens
2+
GITHUB_TOKEN=your_github_token # Requires 'repo' scope
3+
4+
# AI Model API keys
5+
OPENAI_API_KEY=your_openai_key

.gitignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependencies
2+
node_modules/
3+
4+
# Build files
5+
dist/
6+
7+
# Environment variables
8+
.env
9+
10+
# IDEs and editors
11+
.idea/
12+
.vscode/
13+
*.swp
14+
*.swo
15+
.DS_Store
16+
*.suo
17+
*.ntvs*
18+
*.njsproj
19+
*.sln
20+
*.sw?

README.md

Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
# Diff Hound
2+
3+
Diff Hound is an automated AI-powered code review tool that posts intelligent, contextual comments directly on pull requests across supported platforms.
4+
5+
Supports GitHub today. GitLab and Bitbucket support are planned.
6+
7+
---
8+
9+
## ✨ Features
10+
11+
- 🧠 Automated code review using OpenAI (Upcoming: Claude, DeepSeek, CodeLlama)
12+
- 💬 Posts inline or summary comments on pull requests
13+
- 🔌 Plug-and-play architecture for models and platforms
14+
- ⚙️ Configurable with JSON/YAML config files and CLI overrides
15+
- 🛠️ Designed for CI/CD pipelines and local runs
16+
- 🧐 Tracks last reviewed commit to avoid duplicate reviews
17+
18+
---
19+
20+
## 🛠️ Installation
21+
22+
### Option 1: Install via npm
23+
24+
```bash
25+
npm install -g diff-hound
26+
```
27+
28+
### Option 2: Install from source
29+
30+
```bash
31+
git clone https://github.com/runtimebug/diff-hound.git
32+
cd diff-hound
33+
npm install
34+
npm run build
35+
npm link
36+
```
37+
38+
---
39+
40+
## 🚀 How to Use
41+
42+
### Step 1: Setup Environment Variables
43+
44+
Copy the provided `.env.example` to `.env` and fill in your credentials:
45+
46+
```bash
47+
cp .env.example .env
48+
```
49+
50+
Then modify with your keys / tokens:
51+
52+
```env
53+
# Platform tokens
54+
GITHUB_TOKEN=your_github_token # Requires 'repo' scope
55+
56+
# AI Model API keys
57+
OPENAI_API_KEY=your_openai_key
58+
```
59+
60+
> 🔐 `GITHUB_TOKEN` is used to fetch PRs and post comments – [get it here](https://github.com/settings/personal-access-tokens)
61+
> 🔐 `OPENAI_API_KEY` is used to generate code reviews via GPT – [get it here](https://platform.openai.com/api-keys)
62+
63+
---
64+
65+
### Step 2: Create a Config File
66+
67+
You can define your config in `.aicodeconfig.json` or `.aicode.yml`:
68+
69+
#### JSON Example (`.aicodeconfig.json`)
70+
71+
```json
72+
{
73+
"provider": "openai",
74+
"model": "gpt-4o", // Or any other openai model
75+
"endpoint": "", // Optional: custom endpoint
76+
"gitProvider": "github",
77+
"repo": "your-username/your-repo",
78+
"dryRun": false,
79+
"verbose": false,
80+
"rules": [
81+
"Prefer const over let when variables are not reassigned",
82+
"Avoid reassigning const variables",
83+
"Add descriptive comments for complex logic",
84+
"Remove unnecessary comments",
85+
"Follow the DRY (Don't Repeat Yourself) principle",
86+
"Use descriptive variable and function names",
87+
"Handle errors appropriately",
88+
"Add type annotations where necessary"
89+
],
90+
"ignoreFiles": ["*.md", "package-lock.json", "yarn.lock", "LICENSE", "*.log"],
91+
"commentStyle": "inline",
92+
"severity": "suggestion"
93+
}
94+
```
95+
96+
#### YAML Example (`.aicode.yml`)
97+
98+
```yaml
99+
provider: openai
100+
model: gpt-4o # Or any other openai model
101+
endpoint: "" # Optional: custom endpoint
102+
gitProvider: github
103+
repo: your-username/your-repo
104+
dryRun: false
105+
verbose: false
106+
commentStyle: inline
107+
severity: suggestion
108+
ignoreFiles:
109+
- "*.md"
110+
- package-lock.json
111+
- yarn.lock
112+
- LICENSE
113+
- "*.log"
114+
rules:
115+
- Prefer const over let when variables are not reassigned
116+
- Avoid reassigning const variables
117+
- Add descriptive comments for complex logic
118+
- Remove unnecessary comments
119+
- Follow the DRY (Don't Repeat Yourself) principle
120+
- Use descriptive variable and function names
121+
- Handle errors appropriately
122+
- Add type annotations where necessary
123+
```
124+
125+
---
126+
127+
### Step 3: Run It
128+
129+
```bash
130+
diff-hound
131+
```
132+
133+
Or override config values via CLI:
134+
135+
```bash
136+
diff-hound --repo=owner/repo --provider=openai --model=gpt-4o --dry-run
137+
```
138+
139+
> Add `--dry-run` to **print comments to console** instead of posting them.
140+
141+
---
142+
143+
### Output Example (Dry Run)
144+
145+
```bash
146+
== Comments for PR #42: Fix input validation ==
147+
148+
src/index.ts:17 —
149+
Prefer `const` over `let` since `userId` is not reassigned.
150+
151+
src/utils/parse.ts:45 —
152+
Consider refactoring to reduce nesting.
153+
```
154+
155+
---
156+
157+
### Optional CLI Flags
158+
159+
| Flag | Short | Description |
160+
| ------------------ | ----- | --------------------------------------- |
161+
| `--provider` | `-p` | AI model provider (e.g. `openai`) |
162+
| `--model` | `-m` | AI model (e.g. `gpt-4o`, `gpt-4`, etc.) |
163+
| `--model-endpoint` | `-e` | Custom API endpoint for the model |
164+
| `--git-provider` | `-g` | Repo platform (default: `github`) |
165+
| `--repo` | `-r` | GitHub repo in format `owner/repo` |
166+
| `--comment-style` | `-s` | `inline` or `summary` |
167+
| `--dry-run` | `-d` | Don’t post comments, only print |
168+
| `--verbose` | `-v` | Enable debug logs |
169+
| `--config-path` | `-c` | Custom config file path |
170+
171+
---
172+
173+
## 🛠️ Development
174+
175+
### Project Structure
176+
177+
```
178+
diff-hound/
179+
├── bin/ # CLI entrypoint
180+
├── src/
181+
│ ├── cli/ # CLI argument parsing
182+
│ ├── config/ # JSON/YAML config handling
183+
│ ├── core/ # Diff parsing, formatting
184+
│ ├── models/ # AI model adapters
185+
│ ├── platforms/ # GitHub, GitLab, etc.
186+
│ └── types/ # TypeScript types
187+
├── .env
188+
├── README.md
189+
```
190+
191+
---
192+
193+
### Add Support for New AI Models
194+
195+
Create a new class in `src/models/` that implements the `CodeReviewModel` interface.
196+
197+
---
198+
199+
### Add Support for New Platforms
200+
201+
Create a new class in `src/platforms/` that implements the `CodeReviewPlatform` interface.
202+
203+
---
204+
205+
## ✅ Next Steps
206+
207+
🔧 Add Winston for production-grade logging
208+
🌐 Implement GitLab and Bitbucket platform adapters
209+
🌍 Add support for other AI model providers (e.g. Anthropic, DeepSeek...)
210+
💻 Add support for running local models (e.g. Ollama, Llama.cpp, Hugging Face transformers)
211+
📤 Add support for webhook triggers (e.g., GitHub Actions, GitLab CI)
212+
🧪 Add unit and integration test suites (Jest or Vitest)
213+
📦 Publish Docker image for CI/CD use
214+
🧩 Enable plugin hooks for custom rule logic
215+
🗂 Add support for reviewing diffs from local branches or patch files
216+
217+
---
218+
219+
## 📜 License
220+
221+
MIT – Use freely, contribute openly.

bin/diff-hound.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/usr/bin/env node
2+
3+
// This is a simple wrapper to run the compiled TypeScript code
4+
require("../dist/index.js");

0 commit comments

Comments
 (0)