codeflow-hook 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +251 -248
- package/bin/codeflow-hook.js +594 -352
- package/package.json +37 -25
package/README.md
CHANGED
|
@@ -1,248 +1,251 @@
|
|
|
1
|
-
# Codeflow Hook - AI-Powered Git Hooks
|
|
2
|
-
|
|
3
|
-
An interactive CI/CD simulator and lightweight pre-push code reviewer that uses Google Gemini AI to analyze your code changes before commits and pushes.
|
|
4
|
-
|
|
5
|
-
## 🚀 Features
|
|
6
|
-
|
|
7
|
-
- **AI Code Review**: Get intelligent code analysis powered by Gemini AI
|
|
8
|
-
- **Automated Git Hooks**: Automatic pre-commit and pre-push checks
|
|
9
|
-
- **CI/CD Simulation**: Simulates full pipeline including tests and security checks
|
|
10
|
-
- **Easy Installation**: Simple CLI setup for any project
|
|
11
|
-
- **Developer-Friendly**: Clear feedback with actionable suggestions
|
|
12
|
-
|
|
13
|
-
## 📦 Installation
|
|
14
|
-
|
|
15
|
-
### Global Installation
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
npm install -g codeflow-hook
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
### Local Installation (for specific projects)
|
|
22
|
-
|
|
23
|
-
```bash
|
|
24
|
-
npm install --save-dev codeflow-hook
|
|
25
|
-
```
|
|
26
|
-
|
|
27
|
-
## ⚙️ Setup
|
|
28
|
-
|
|
29
|
-
### 1. Configure AI Provider
|
|
30
|
-
|
|
31
|
-
Choose your AI provider and configure with your API key:
|
|
32
|
-
|
|
33
|
-
**Gemini (default):**
|
|
34
|
-
```bash
|
|
35
|
-
codeflow-hook config -p gemini -k YOUR_GEMINI_API_KEY
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
-
|
|
102
|
-
|
|
103
|
-
-
|
|
104
|
-
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
-
|
|
111
|
-
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
#
|
|
122
|
-
git
|
|
123
|
-
|
|
124
|
-
# Pre-
|
|
125
|
-
git
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
# Analyze
|
|
135
|
-
git diff
|
|
136
|
-
|
|
137
|
-
# Analyze
|
|
138
|
-
git diff
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
- **
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
"
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
```
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
1
|
+
# Codeflow Hook - AI-Powered Git Hooks
|
|
2
|
+
|
|
3
|
+
An interactive CI/CD simulator and lightweight pre-push code reviewer that uses Google Gemini AI to analyze your code changes before commits and pushes.
|
|
4
|
+
|
|
5
|
+
## 🚀 Features
|
|
6
|
+
|
|
7
|
+
- **AI Code Review**: Get intelligent code analysis powered by Gemini AI
|
|
8
|
+
- **Automated Git Hooks**: Automatic pre-commit and pre-push checks
|
|
9
|
+
- **CI/CD Simulation**: Simulates full pipeline including tests and security checks
|
|
10
|
+
- **Easy Installation**: Simple CLI setup for any project
|
|
11
|
+
- **Developer-Friendly**: Clear feedback with actionable suggestions
|
|
12
|
+
|
|
13
|
+
## 📦 Installation
|
|
14
|
+
|
|
15
|
+
### Global Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install -g codeflow-hook
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Local Installation (for specific projects)
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
npm install --save-dev codeflow-hook
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## ⚙️ Setup
|
|
28
|
+
|
|
29
|
+
### 1. Configure AI Provider
|
|
30
|
+
|
|
31
|
+
Choose your AI provider and configure with your API key:
|
|
32
|
+
|
|
33
|
+
**Gemini (default):**
|
|
34
|
+
```bash
|
|
35
|
+
codeflow-hook config -p gemini -k YOUR_GEMINI_API_KEY
|
|
36
|
+
```
|
|
37
|
+
*You'll be prompted to select a model: `gemini-1.5-pro-latest`, `gemini-1.5-flash-latest`, or `gemini-pro`*
|
|
38
|
+
|
|
39
|
+
**OpenAI:**
|
|
40
|
+
```bash
|
|
41
|
+
codeflow-hook config -p openai -k YOUR_OPENAI_API_KEY
|
|
42
|
+
```
|
|
43
|
+
*You'll be prompted to select a model: `gpt-4o`, `gpt-4-turbo`, `gpt-4`, or `gpt-3.5-turbo`*
|
|
44
|
+
|
|
45
|
+
**Claude/Anthropic:**
|
|
46
|
+
```bash
|
|
47
|
+
codeflow-hook config -p claude -k YOUR_CLAUDE_API_KEY
|
|
48
|
+
```
|
|
49
|
+
*You'll be prompted to select a model: `claude-3-opus-20240229`, `claude-3-sonnet-20240229`, or `claude-3-haiku-20240307`*
|
|
50
|
+
|
|
51
|
+
**Custom model/URL:**
|
|
52
|
+
```bash
|
|
53
|
+
codeflow-hook config -p openai -k YOUR_API_KEY -m gpt-3.5-turbo -u https://your-custom-endpoint.com
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
### 2. Install Git Hooks
|
|
57
|
+
|
|
58
|
+
In your project directory:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
codeflow-hook install
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
This creates:
|
|
65
|
+
- `pre-commit`: AI analysis of staged changes
|
|
66
|
+
- `pre-push`: Full CI/CD simulation (tests + AI review)
|
|
67
|
+
|
|
68
|
+
### 3. Check Status
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
codeflow-hook status
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## 🛠️ Commands
|
|
75
|
+
|
|
76
|
+
### Analyze Specific Changes
|
|
77
|
+
|
|
78
|
+
Manually analyze a git diff:
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
git diff --staged | codeflow-hook analyze-diff
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### Reinstall Hooks
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
codeflow-hook install --hooks-dir .custom-hooks
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### View Help
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
codeflow-hook --help
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
## 🔄 How It Works
|
|
97
|
+
|
|
98
|
+
### Pre-commit Hook
|
|
99
|
+
- Analyzes staged changes only
|
|
100
|
+
- Provides quick feedback on code quality
|
|
101
|
+
- Prevents problematic commits
|
|
102
|
+
|
|
103
|
+
### Pre-push Hook
|
|
104
|
+
- Runs full test suite
|
|
105
|
+
- Performs comprehensive AI code review
|
|
106
|
+
- Simulates deployment pipeline
|
|
107
|
+
- Blocks pushes with failing checks
|
|
108
|
+
|
|
109
|
+
### AI Analysis Features
|
|
110
|
+
- Code quality assessment
|
|
111
|
+
- Security vulnerability detection
|
|
112
|
+
- Performance optimization suggestions
|
|
113
|
+
- Best practice recommendations
|
|
114
|
+
- Maintainability evaluation
|
|
115
|
+
|
|
116
|
+
## 💡 Usage Examples
|
|
117
|
+
|
|
118
|
+
### Standard Development Workflow
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
# Stage your changes
|
|
122
|
+
git add .
|
|
123
|
+
|
|
124
|
+
# Pre-commit hook automatically runs AI analysis
|
|
125
|
+
git commit -m "feat: add new authentication"
|
|
126
|
+
|
|
127
|
+
# Pre-push hook runs tests and full AI review
|
|
128
|
+
git push origin main
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Manual Analysis
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
# Analyze uncommitted changes
|
|
135
|
+
git diff | codeflow-hook analyze-diff
|
|
136
|
+
|
|
137
|
+
# Analyze specific files
|
|
138
|
+
git diff path/to/file.js | codeflow-hook analyze-diff
|
|
139
|
+
|
|
140
|
+
# Analyze between commits
|
|
141
|
+
git diff HEAD~1 HEAD | codeflow-hook analyze-diff
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## 🎯 AI Analysis Output
|
|
145
|
+
|
|
146
|
+
The tool provides:
|
|
147
|
+
|
|
148
|
+
- **Rating**: 1-10 quality score with color coding
|
|
149
|
+
- **Summary**: Brief assessment of changes
|
|
150
|
+
- **Issues**: Specific problems with solutions
|
|
151
|
+
- **Recommendations**: Improvement suggestions
|
|
152
|
+
|
|
153
|
+
Example output:
|
|
154
|
+
```
|
|
155
|
+
⭐ **Rating:** 9/10
|
|
156
|
+
📝 **Summary:** Clean implementation with good separation of concerns
|
|
157
|
+
|
|
158
|
+
⚠️ **Issues:**
|
|
159
|
+
- Consider adding input validation for edge cases
|
|
160
|
+
|
|
161
|
+
💡 **Recommendations:**
|
|
162
|
+
- Add comprehensive error handling
|
|
163
|
+
- Consider extracting common logic to a utility function
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## 🔧 Configuration
|
|
167
|
+
|
|
168
|
+
Configuration is stored in `~/.codeflow-hook/config.json`:
|
|
169
|
+
|
|
170
|
+
```json
|
|
171
|
+
{
|
|
172
|
+
"provider": "gemini",
|
|
173
|
+
"apiKey": "your-api-key",
|
|
174
|
+
"apiUrl": "https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent",
|
|
175
|
+
"model": "gemini-pro"
|
|
176
|
+
}
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
### Supported AI Providers
|
|
180
|
+
|
|
181
|
+
- **Gemini**: `provider: "gemini"` - Default, uses Google AI
|
|
182
|
+
- **OpenAI**: `provider: "openai"` - GPT models
|
|
183
|
+
- **Claude**: `provider: "claude"` - Anthropic models
|
|
184
|
+
|
|
185
|
+
Each provider has optimized prompts and supports custom endpoints.
|
|
186
|
+
|
|
187
|
+
## 📋 Requirements
|
|
188
|
+
|
|
189
|
+
- Node.js 16+
|
|
190
|
+
- Git repository
|
|
191
|
+
- Gemini API key
|
|
192
|
+
|
|
193
|
+
## 🔒 Security
|
|
194
|
+
|
|
195
|
+
- API keys stored locally (not in your repo)
|
|
196
|
+
- Have to make an .env file for the credentials
|
|
197
|
+
- No data sent to third parties except Google Gemini
|
|
198
|
+
- Code diffs analyzed locally before sending
|
|
199
|
+
|
|
200
|
+
## 🐛 Troubleshooting
|
|
201
|
+
|
|
202
|
+
### Common Issues
|
|
203
|
+
|
|
204
|
+
**"No configuration found"**
|
|
205
|
+
```bash
|
|
206
|
+
codeflow-hook config -k YOUR_API_KEY
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
**Hooks not running**
|
|
210
|
+
```bash
|
|
211
|
+
codeflow-hook install
|
|
212
|
+
# Ensure scripts are executable
|
|
213
|
+
chmod +x .git/hooks/pre-commit .git/hooks/pre-push
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
**API errors**
|
|
217
|
+
- Verify your API key is valid
|
|
218
|
+
- Check Gemini API service status
|
|
219
|
+
- Ensure you have quota remaining
|
|
220
|
+
|
|
221
|
+
### Manual Hook Setup
|
|
222
|
+
|
|
223
|
+
If automatic installation fails:
|
|
224
|
+
|
|
225
|
+
1. Create `.git/hooks/pre-commit`
|
|
226
|
+
2. Add executable permissions: `chmod +x .git/hooks/pre-commit`
|
|
227
|
+
3. Call the CLI: `npx codeflow-hook analyze-diff "$(git diff --cached)"`
|
|
228
|
+
|
|
229
|
+
## 🤝 Contributing
|
|
230
|
+
|
|
231
|
+
1. Fork the repository
|
|
232
|
+
2. Create a feature branch
|
|
233
|
+
3. Make your changes
|
|
234
|
+
4. Run tests: `npm test`
|
|
235
|
+
5. Submit a pull request
|
|
236
|
+
|
|
237
|
+
## 📄 License
|
|
238
|
+
|
|
239
|
+
MIT License - see LICENSE file for details
|
|
240
|
+
|
|
241
|
+
## 🎉 Acknowledgments
|
|
242
|
+
|
|
243
|
+
Built with ❤️ using:
|
|
244
|
+
- Google Gemini AI
|
|
245
|
+
- Commander.js for CLI
|
|
246
|
+
- Chalk for terminal colors
|
|
247
|
+
- Ora for loading spinners
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
**Ready to supercharge your development workflow? Install Codeflow Hook today!**
|