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