gitpal-cli 1.0.1 → 1.0.2

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 CHANGED
@@ -0,0 +1,308 @@
1
+ # šŸ¤– GitPal — AI-Powered Git Assistant CLI
2
+ <!--
3
+ > Stop writing commit messages manually. Let AI do it in 3 seconds.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/gitpal-cli.svg?style=flat-square)](https://www.npmjs.com/package/gitpal-cli)
6
+ [![npm downloads](https://img.shields.io/npm/dm/gitpal-cli.svg?style=flat-square)](https://www.npmjs.com/package/gitpal-cli)
7
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg?style=flat-square)](https://opensource.org/licenses/MIT)
8
+ [![Node.js](https://img.shields.io/badge/Node.js-18%2B-green?style=flat-square)](https://nodejs.org) -->
9
+
10
+ ---
11
+
12
+ ## 😤 The Problem Every Developer Faces
13
+
14
+ ```bash
15
+ # You just coded for 2 hours and now...
16
+ git add .
17
+ git commit -m "fix" # 😭 lazy and meaningless
18
+ git commit -m "changes" # 😭 tells nothing
19
+ git commit -m "update" # 😭 useless history
20
+ ```
21
+
22
+ **Your git log becomes a mess. Your team hates you. You hate yourself.**
23
+
24
+ ---
25
+
26
+ ## ✨ The Solution
27
+
28
+ ```bash
29
+ git add .
30
+ gitpal commit
31
+
32
+ # āœ” Staged changes found.
33
+ # āœ” Commit message generated!
34
+ #
35
+ # Suggested: feat(auth): add bcrypt password hashing to login endpoint
36
+ #
37
+ # ? Use this message? › Yes
38
+ # āœ… Committed successfully!
39
+ ```
40
+
41
+ **GitPal reads your actual code changes and writes the perfect commit message. Every time.**
42
+
43
+ ---
44
+
45
+ ## šŸš€ Quick Start
46
+
47
+ ```bash
48
+ # Install globally
49
+ npm install -g gitpal-cli
50
+
51
+ # Setup your AI provider (one time only — it's free!)
52
+ gitpal config
53
+
54
+ # Use in any project
55
+ cd your-project
56
+ git add .
57
+ gitpal commit
58
+ ```
59
+
60
+ **That's it. You're done.**
61
+
62
+ ---
63
+
64
+ ## šŸ¤– Supports 4 AI Providers
65
+
66
+ Pick any one — all work perfectly:
67
+
68
+ | Provider | Model | Cost | Speed |
69
+ |---|---|---|---|
70
+ | **Groq** | llama-3.3-70b | šŸ†“ Free | ⚔ Fastest |
71
+ | **Google Gemini** | gemini-pro | šŸ†“ Free tier | āœ… Fast |
72
+ | **Anthropic** | claude-3-haiku | šŸ’° Free credits | āœ… Fast |
73
+ | **OpenAI** | gpt-3.5-turbo | šŸ’° Paid | āœ… Fast |
74
+
75
+ > šŸ’” Recommended for beginners: **Groq** — completely free, no credit card needed. Get your key at [console.groq.com](https://console.groq.com)
76
+
77
+ ---
78
+
79
+ ## šŸ“– All Commands
80
+
81
+ ### `gitpal commit` — AI Commit Messages
82
+ Reads your staged diff and generates a meaningful conventional commit message.
83
+
84
+ ```bash
85
+ git add src/payment.js
86
+ gitpal commit
87
+
88
+ # āœ” Commit message generated!
89
+ # Suggested: feat(payment): integrate Razorpay with webhook support
90
+ # ? Use this message? › Yes / Edit / Cancel
91
+ # āœ… Committed!
92
+ ```
93
+
94
+ **Options:**
95
+ ```bash
96
+ gitpal commit --yes # Skip confirmation, commit directly
97
+ ```
98
+
99
+ ---
100
+
101
+ ### `gitpal summary` — Plain English Summary
102
+ Summarizes your recent commits so you always know what you built.
103
+
104
+ ```bash
105
+ gitpal summary --last 7
106
+
107
+ # šŸ“‹ Summary of last 7 commits:
108
+ # • Built user authentication system with JWT tokens
109
+ # • Integrated Razorpay payment gateway
110
+ # • Fixed cart total calculation for discounted items
111
+ # • Added dark mode to the dashboard
112
+ # • Improved API response time using Redis caching
113
+ ```
114
+
115
+ **Options:**
116
+ ```bash
117
+ gitpal summary --last 10 # Summarize last 10 commits
118
+ ```
119
+
120
+ ---
121
+
122
+ ### `gitpal pr` — Pull Request Descriptions
123
+ Generates a complete PR description from your branch diff. Copy-paste straight into GitHub.
124
+
125
+ ```bash
126
+ gitpal pr --base main
127
+
128
+ # šŸ“ Pull Request Description:
129
+ #
130
+ # ## What changed
131
+ # - Integrated Razorpay payment gateway
132
+ # - Added webhook handler for payment confirmation
133
+ # - Added retry logic for failed transactions
134
+ #
135
+ # ## Why
136
+ # - App needed real payment processing for production launch
137
+ #
138
+ # ## Type of change
139
+ # New feature
140
+ #
141
+ # ## Testing
142
+ # Use test card: 4111 1111 1111 1111
143
+ ```
144
+
145
+ **Options:**
146
+ ```bash
147
+ gitpal pr --base develop # Compare against develop branch
148
+ ```
149
+
150
+ ---
151
+
152
+ ### `gitpal changelog` — Release Changelog
153
+ Auto-generates a formatted changelog entry from your commit history.
154
+
155
+ ```bash
156
+ gitpal changelog --ver 2.0.0
157
+
158
+ # šŸ“„ CHANGELOG v2.0.0:
159
+ #
160
+ # ## [2.0.0] - 2026-03-21
161
+ #
162
+ # ### Features
163
+ # - Payment gateway integration
164
+ # - Dark mode support
165
+ # - User authentication system
166
+ #
167
+ # ### Bug Fixes
168
+ # - Fixed cart calculation for discounts
169
+ # - Fixed mobile layout on small screens
170
+ #
171
+ # ### Improvements
172
+ # - 40% faster API response time
173
+ # - Reduced bundle size by 20%
174
+ ```
175
+
176
+ ---
177
+
178
+ ### `gitpal config` — Setup AI Provider
179
+ Interactive setup to configure your AI provider and API key.
180
+
181
+ ```bash
182
+ gitpal config
183
+
184
+ # ? Choose your AI provider:
185
+ # āÆ Groq — llama3 (Free & Ultra Fast)
186
+ # Anthropic (Claude)
187
+ # OpenAI (GPT-3.5)
188
+ # Google Gemini
189
+ #
190
+ # ? Enter your API key: ****************
191
+ # āœ… Configuration saved!
192
+ ```
193
+
194
+ ---
195
+
196
+ ## šŸ”„ Full Daily Workflow
197
+
198
+ ```
199
+ Morning — open your project
200
+ ↓
201
+ Write some code (auth feature)
202
+ ↓
203
+ git add .
204
+ gitpal commit → "feat(auth): add Google OAuth login"
205
+ ↓
206
+ Write more code (fix a bug)
207
+ ↓
208
+ git add .
209
+ gitpal commit → "fix(cart): resolve total miscalculation"
210
+ ↓
211
+ End of day
212
+ gitpal summary → "Built OAuth, fixed cart bug, added tests"
213
+ ↓
214
+ Ready to merge?
215
+ gitpal pr → Full PR description, copy to GitHub
216
+ ↓
217
+ Releasing v2.0?
218
+ gitpal changelog --ver 2.0.0 → Full changelog ready
219
+ ```
220
+
221
+ ---
222
+
223
+ ## šŸ’” Why GitPal?
224
+
225
+ | Without GitPal | With GitPal |
226
+ |---|---|
227
+ | `git commit -m "fix"` | `feat(auth): add JWT token refresh logic` |
228
+ | Spend 15 mins on PR description | Generated in 3 seconds |
229
+ | Forget what you built last week | Plain English summary instantly |
230
+ | Write changelog manually | Auto-generated from commits |
231
+ | Works with one AI only | Works with 4 AI providers |
232
+
233
+ ---
234
+
235
+ ## šŸ—‚ Project Structure
236
+
237
+ ```
238
+ gitpal/
239
+ ā”œā”€ā”€ bin/
240
+ │ └── gitpal.js ← CLI executable
241
+ ā”œā”€ā”€ src/
242
+ │ ā”œā”€ā”€ index.js ← Main CLI entry (Commander)
243
+ │ ā”œā”€ā”€ ai.js ← Multi-provider AI router
244
+ │ ā”œā”€ā”€ git.js ← Git operations
245
+ │ └── commands/
246
+ │ ā”œā”€ā”€ commit.js ← gitpal commit
247
+ │ ā”œā”€ā”€ summary.js ← gitpal summary
248
+ │ ā”œā”€ā”€ pr.js ← gitpal pr
249
+ │ ā”œā”€ā”€ changelog.js ← gitpal changelog
250
+ │ └── config.js ← gitpal config
251
+ └── tests/
252
+ └── ai.test.js
253
+ ```
254
+
255
+ ---
256
+
257
+ ## šŸ›  Local Development
258
+
259
+ ```bash
260
+ # Clone the repo
261
+ git clone https://github.com/harshit_gangwar16/gitpal
262
+ cd gitpal
263
+
264
+ # Install dependencies
265
+ npm install
266
+
267
+ # Link globally for testing
268
+ npm link
269
+
270
+ # Configure AI provider
271
+ gitpal config
272
+
273
+ # Try it out
274
+ git add .
275
+ gitpal commit
276
+ ```
277
+
278
+ ---
279
+
280
+ ## šŸ¤ Contributing
281
+
282
+ Contributions are welcome! To add a new AI provider:
283
+
284
+ 1. Open `src/ai.js`
285
+ 2. Add a new `callProviderName(prompt, apiKey)` function
286
+ 3. Add a new case in the `askAI()` switch statement
287
+ 4. Submit a PR
288
+
289
+ ---
290
+
291
+ ## šŸ‘Øā€šŸ’» Author
292
+
293
+ Built by **Harshit Gangwar**
294
+
295
+ - GitHub: [@harshit_gangwar16](https://github.com/harshit_gangwar16)
296
+ - npm: [gitpal-cli](https://www.npmjs.com/package/gitpal-cli)
297
+
298
+ ---
299
+
300
+ ## šŸ“„ License
301
+
302
+ MIT — free to use, modify and distribute.
303
+
304
+ ---
305
+
306
+ <p align="center">
307
+ <strong>If GitPal saves you time, give it a ⭐ on GitHub!</strong>
308
+ </p>
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "gitpal-cli",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "AI-powered Git assistant CLI",
5
5
  "main": "src/index.js",
6
6
  "bin": {
7
- "gitpal": "bin/gitpal.js"
7
+ "gitpal": "./bin/gitpal.js"
8
8
  },
9
9
  "scripts": {
10
10
  "test": "node --experimental-vm-modules node_modules/.bin/jest"
@@ -9,7 +9,7 @@ export async function changelogCommand(options) {
9
9
  process.exit(1);
10
10
  }
11
11
 
12
- const version = options.ver || "1.0.0";
12
+ const version = options.version || "1.0.0";
13
13
  const n = options.last || 20;
14
14
 
15
15
  const spinner = ora(`Fetching last ${n} commits for changelog...`).start();
@@ -0,0 +1,199 @@
1
+ import chalk from 'chalk';
2
+ import ora from 'ora';
3
+ import inquirer from 'inquirer';
4
+ import { getStagedDiff, doCommit, isGitRepo } from '../git.js';
5
+ import { askAI } from '../ai.js';
6
+
7
+ export async function reviewCommand(options) {
8
+ // 1. Guard: must be inside a git repo
9
+ if (!(await isGitRepo())) {
10
+ console.log(chalk.red('āŒ Not a git repository.'));
11
+ process.exit(1);
12
+ }
13
+
14
+ // 2. Get staged diff
15
+ const spinner = ora('Reading your staged changes...').start();
16
+ const diff = await getStagedDiff();
17
+
18
+ if (!diff || diff.trim() === '') {
19
+ spinner.fail(chalk.yellow('No staged changes found. Run: git add <files>'));
20
+ process.exit(1);
21
+ }
22
+ spinner.succeed('Staged changes found.');
23
+
24
+ // 3. Send to AI for review
25
+ const aiSpinner = ora('AI is reviewing your code...').start();
26
+
27
+ const prompt = `You are a senior software engineer doing a code review. Analyze this git diff carefully.
28
+
29
+ Review the code for:
30
+ 1. Bugs or logic errors
31
+ 2. Security issues (SQL injection, plain text passwords, exposed keys, etc.)
32
+ 3. Missing error handling
33
+ 4. Performance issues
34
+ 5. Bad practices or code smells
35
+ 6. Suggestions for improvement
36
+
37
+ Format your response EXACTLY like this:
38
+ BUGS:
39
+ - (list any bugs found, or "None found")
40
+
41
+ SECURITY:
42
+ - (list any security issues, or "None found")
43
+
44
+ IMPROVEMENTS:
45
+ - (list suggestions, or "None found")
46
+
47
+ VERDICT: (one of: "Good to commit", "Commit with caution", "Do not commit")
48
+
49
+ Be specific — mention file names and line numbers when possible.
50
+ Keep each point short and clear.
51
+
52
+ Git Diff:
53
+ ${diff.slice(0, 4000)}`;
54
+
55
+ let review;
56
+ try {
57
+ review = await askAI(prompt);
58
+ aiSpinner.succeed(chalk.green('Code review complete!\n'));
59
+ } catch (err) {
60
+ aiSpinner.fail(chalk.red(`AI Error: ${err.message}`));
61
+ process.exit(1);
62
+ }
63
+
64
+ // 4. Parse and display review nicely
65
+ const lines = review.split('\n');
66
+
67
+ lines.forEach(line => {
68
+ const trimmed = line.trim();
69
+ if (!trimmed) return;
70
+
71
+ if (trimmed.startsWith('BUGS:')) {
72
+ console.log(chalk.red.bold('\nšŸ› Bugs Found:'));
73
+ } else if (trimmed.startsWith('SECURITY:')) {
74
+ console.log(chalk.yellow.bold('\nšŸ”’ Security Issues:'));
75
+ } else if (trimmed.startsWith('IMPROVEMENTS:')) {
76
+ console.log(chalk.blue.bold('\nšŸ’” Improvements:'));
77
+ } else if (trimmed.startsWith('VERDICT:')) {
78
+ const verdict = trimmed.replace('VERDICT:', '').trim();
79
+ console.log('');
80
+ if (verdict.includes('Good to commit')) {
81
+ console.log(chalk.green.bold(`āœ… Verdict: ${verdict}`));
82
+ } else if (verdict.includes('caution')) {
83
+ console.log(chalk.yellow.bold(`āš ļø Verdict: ${verdict}`));
84
+ } else {
85
+ console.log(chalk.red.bold(`āŒ Verdict: ${verdict}`));
86
+ }
87
+ } else if (trimmed.startsWith('-')) {
88
+ // Check content to pick color
89
+ const lower = trimmed.toLowerCase();
90
+ if (lower.includes('none found')) {
91
+ console.log(chalk.green(` ${trimmed}`));
92
+ } else if (
93
+ lower.includes('bug') || lower.includes('error') ||
94
+ lower.includes('crash') || lower.includes('undefined')
95
+ ) {
96
+ console.log(chalk.red(` ${trimmed}`));
97
+ } else if (
98
+ lower.includes('security') || lower.includes('password') ||
99
+ lower.includes('injection') || lower.includes('exposed')
100
+ ) {
101
+ console.log(chalk.yellow(` ${trimmed}`));
102
+ } else {
103
+ console.log(chalk.cyan(` ${trimmed}`));
104
+ }
105
+ } else {
106
+ console.log(chalk.white(` ${trimmed}`));
107
+ }
108
+ });
109
+
110
+ console.log('');
111
+
112
+ // 5. Ask what to do next
113
+ if (options.reviewOnly) return;
114
+
115
+ const { action } = await inquirer.prompt([
116
+ {
117
+ type: 'list',
118
+ name: 'action',
119
+ message: 'What would you like to do?',
120
+ choices: [
121
+ { name: 'āœ… Looks good — generate commit message and commit', value: 'commit' },
122
+ { name: 'šŸ‘€ Review looks fine — just show me the diff again', value: 'diff' },
123
+ { name: 'āŒ I will fix the issues first', value: 'cancel' },
124
+ ],
125
+ },
126
+ ]);
127
+
128
+ if (action === 'cancel') {
129
+ console.log(chalk.yellow('\nSmart choice! Fix the issues and run gitpal review again.'));
130
+ return;
131
+ }
132
+
133
+ if (action === 'diff') {
134
+ console.log(chalk.dim('\n--- Staged Diff ---'));
135
+ console.log(chalk.white(diff.slice(0, 2000)));
136
+ return;
137
+ }
138
+
139
+ if (action === 'commit') {
140
+ // Auto generate commit message after review
141
+ const commitSpinner = ora('Generating commit message...').start();
142
+
143
+ const commitPrompt = `You are an expert developer. Analyze this git diff and write a concise conventional commit message.
144
+
145
+ Rules:
146
+ - Use conventional commits format: type(scope): description
147
+ - Types: feat, fix, docs, style, refactor, test, chore
148
+ - Keep it under 72 characters
149
+ - Return ONLY the commit message, nothing else
150
+
151
+ Git Diff:
152
+ ${diff.slice(0, 3000)}`;
153
+
154
+ try {
155
+ const message = await askAI(commitPrompt);
156
+ commitSpinner.succeed(chalk.green('Commit message generated!'));
157
+
158
+ console.log('\n' + chalk.bold('Suggested commit message:'));
159
+ console.log(chalk.cyan(` ${message}\n`));
160
+
161
+ const { confirm } = await inquirer.prompt([
162
+ {
163
+ type: 'list',
164
+ name: 'confirm',
165
+ message: 'Commit with this message?',
166
+ choices: [
167
+ { name: 'āœ… Yes, commit', value: 'yes' },
168
+ { name: 'āœļø Edit message', value: 'edit' },
169
+ { name: 'āŒ Cancel', value: 'cancel' },
170
+ ],
171
+ },
172
+ ]);
173
+
174
+ if (confirm === 'cancel') {
175
+ console.log(chalk.yellow('Cancelled.'));
176
+ return;
177
+ }
178
+
179
+ let finalMessage = message;
180
+ if (confirm === 'edit') {
181
+ const { edited } = await inquirer.prompt([
182
+ {
183
+ type: 'input',
184
+ name: 'edited',
185
+ message: 'Edit commit message:',
186
+ default: message,
187
+ },
188
+ ]);
189
+ finalMessage = edited;
190
+ }
191
+
192
+ await doCommit(finalMessage);
193
+ console.log(chalk.green.bold('\nāœ… Reviewed and committed successfully!'));
194
+
195
+ } catch (err) {
196
+ commitSpinner.fail(chalk.red(`Error: ${err.message}`));
197
+ }
198
+ }
199
+ }
package/src/index.js CHANGED
@@ -5,6 +5,7 @@ import { summaryCommand } from './commands/summary.js';
5
5
  import { prCommand } from './commands/pr.js';
6
6
  import { changelogCommand } from './commands/changelog.js';
7
7
  import { configCommand } from './commands/config.js';
8
+ import { reviewCommand } from './commands/review.js';
8
9
 
9
10
  const program = new Command();
10
11
 
@@ -37,7 +38,7 @@ program
37
38
  program
38
39
  .command('changelog')
39
40
  .description('Generate a changelog from commit history')
40
- .option('-v, --ver <version>', 'Version number for changelog', '1.0.0')
41
+ .option('-v, --version <version>', 'Version number for changelog', '1.0.0')
41
42
  .option('-n, --last <number>', 'Number of commits to include', '20')
42
43
  .action(changelogCommand);
43
44
 
@@ -46,6 +47,13 @@ program
46
47
  .description('Configure your AI provider and API key')
47
48
  .action(configCommand);
48
49
 
50
+ program
51
+ .command('review')
52
+ .description('AI reviews your code for bugs and issues before committing')
53
+ .option('-r, --review-only', 'Only review, do not commit')
54
+ .action(reviewCommand);
55
+
56
+
49
57
  program.parse(process.argv);
50
58
 
51
59
  // Show help if no command given