gims 0.4.3 → 0.4.4
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/.github/workflows/release.yml +39 -0
- package/CLAUDE.md +43 -0
- package/LICENSE +21 -0
- package/README.md +191 -74
- package/bin/gims.js +99 -16
- package/package.json +1 -1
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
name: Publish to npm
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build-and-publish:
|
|
9
|
+
runs-on: ubuntu-latest
|
|
10
|
+
|
|
11
|
+
steps:
|
|
12
|
+
- name: Checkout repository
|
|
13
|
+
uses: actions/checkout@v4
|
|
14
|
+
|
|
15
|
+
- name: Set up Node.js
|
|
16
|
+
uses: actions/setup-node@v4
|
|
17
|
+
with:
|
|
18
|
+
node-version: 20
|
|
19
|
+
cache: 'npm'
|
|
20
|
+
registry-url: 'https://registry.npmjs.org/'
|
|
21
|
+
|
|
22
|
+
- name: Install dependencies
|
|
23
|
+
run: npm ci
|
|
24
|
+
|
|
25
|
+
- name: Run tests
|
|
26
|
+
run: npm test
|
|
27
|
+
|
|
28
|
+
- name: Set Git identity
|
|
29
|
+
run: |
|
|
30
|
+
git config user.name "github-actions[bot]"
|
|
31
|
+
git config user.email "github-actions[bot]@users.noreply.github.com"
|
|
32
|
+
|
|
33
|
+
- name: Bump version
|
|
34
|
+
run: npm version patch --no-git-tag-version
|
|
35
|
+
|
|
36
|
+
- name: Publish to npm
|
|
37
|
+
run: npm publish
|
|
38
|
+
env:
|
|
39
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
|
package/CLAUDE.md
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
# CLAUDE.md
|
|
2
|
+
|
|
3
|
+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
|
|
4
|
+
|
|
5
|
+
## Project Overview
|
|
6
|
+
|
|
7
|
+
GIMS (Git Made Simple) is an AI-powered Git CLI tool that automatically generates meaningful commit messages from code changes. It's a Node.js package published to npm that integrates with OpenAI GPT-4 and Google Gemini APIs.
|
|
8
|
+
|
|
9
|
+
## Architecture
|
|
10
|
+
|
|
11
|
+
- **Single-file CLI**: All functionality is contained in `bin/gims.js`
|
|
12
|
+
- **AI Integration**: Supports both OpenAI and Google Gemini APIs with intelligent fallback strategies
|
|
13
|
+
- **Git Wrapper**: Built on top of `simple-git` library for Git operations
|
|
14
|
+
- **Token Management**: Implements sophisticated content chunking to handle large diffs within AI token limits
|
|
15
|
+
|
|
16
|
+
## Key Components
|
|
17
|
+
|
|
18
|
+
- **Command System**: Uses `commander.js` for CLI argument parsing with aliases (e.g., `g o` for `gims online`)
|
|
19
|
+
- **AI Message Generation**: Multi-strategy approach that falls back from full diff → summary → status → truncated content
|
|
20
|
+
- **Commit Resolution**: Supports both commit hashes and numbered indices for referencing commits
|
|
21
|
+
- **Safe Operations**: Includes error handling for empty repositories and edge cases
|
|
22
|
+
|
|
23
|
+
## Environment Setup
|
|
24
|
+
|
|
25
|
+
Required environment variables (at least one):
|
|
26
|
+
- `OPENAI_API_KEY` - For OpenAI GPT-4o-mini integration
|
|
27
|
+
- `GEMINI_API_KEY` - For Google Gemini 2.0 Flash integration
|
|
28
|
+
|
|
29
|
+
## Common Commands
|
|
30
|
+
|
|
31
|
+
- **Install globally**: `npm install -g .`
|
|
32
|
+
- **Test locally**: `node bin/gims.js --help`
|
|
33
|
+
- **Test specific command**: `node bin/gims.js suggest`
|
|
34
|
+
- **Run with alias**: `g o` (after global install)
|
|
35
|
+
|
|
36
|
+
## Development Notes
|
|
37
|
+
|
|
38
|
+
- No test framework is currently configured (package.json shows placeholder test script)
|
|
39
|
+
- Node.js version requirement: >=20.0.0
|
|
40
|
+
- Uses CommonJS modules (`require`/`module.exports`)
|
|
41
|
+
- Dependencies are minimal and focused on core functionality
|
|
42
|
+
- Token estimation uses 4 characters per token approximation
|
|
43
|
+
- Maximum context limit set conservatively at 100,000 tokens
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Sairaj Jawalikar
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,140 +1,257 @@
|
|
|
1
|
+
# 🚀 GIMS - Git Made Simple
|
|
1
2
|
|
|
3
|
+
<div align="center">
|
|
4
|
+
|
|
5
|
+
[](https://npmjs.org/package/gims)
|
|
6
|
+
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://nodejs.org/)
|
|
8
|
+
[](https://github.com/s41r4j/gims)
|
|
2
9
|
|
|
3
|
-
|
|
10
|
+
**The AI-powered Git CLI that writes your commit messages for you**
|
|
11
|
+
|
|
12
|
+
*Because life's too short for "fix stuff" commits* 🎯
|
|
4
13
|
|
|
5
|
-
|
|
6
|
-
npm install -g gims
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
This installs the `gims` command and a shortcut alias:
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
g # shortcut for gims
|
|
13
|
-
```
|
|
14
|
+
</div>
|
|
14
15
|
|
|
15
16
|
---
|
|
16
17
|
|
|
17
|
-
##
|
|
18
|
+
## ✨ What is GIMS?
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
GIMS is a revolutionary Git CLI tool that uses AI to automatically generate meaningful commit messages from your code changes. Say goodbye to generic "update code" commits and hello to descriptive, professional commit messages that actually tell a story.
|
|
20
21
|
|
|
21
|
-
###
|
|
22
|
+
### 🎬 See It In Action
|
|
22
23
|
|
|
23
24
|
```bash
|
|
24
|
-
|
|
25
|
+
# Traditional Git workflow 😴
|
|
26
|
+
git add .
|
|
27
|
+
git commit -m "update stuff" # 🤦♂️
|
|
28
|
+
git push
|
|
29
|
+
|
|
30
|
+
# GIMS workflow ⚡
|
|
31
|
+
g o # AI analyzes changes, commits with perfect message, and pushes!
|
|
25
32
|
```
|
|
26
33
|
|
|
27
|
-
|
|
34
|
+
## 🌟 Features
|
|
28
35
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
36
|
+
### 🤖 **AI-Powered Commit Messages**
|
|
37
|
+
- **OpenAI GPT-4o-mini** integration for intelligent commit message generation
|
|
38
|
+
- **Google Gemini 2.0 Flash** support for lightning-fast analysis
|
|
39
|
+
- Smart diff analysis that understands your code changes
|
|
40
|
+
- Handles large codebases with intelligent summarization and token management
|
|
32
41
|
|
|
33
|
-
|
|
42
|
+
### ⚡ **Lightning Fast Workflow**
|
|
43
|
+
- **One command commits**: `g o` - analyze, commit, and push in seconds
|
|
44
|
+
- **Smart suggestions**: `g s` - get AI-generated messages copied to clipboard
|
|
45
|
+
- **Local commits**: `g l` - commit locally with AI messages
|
|
46
|
+
- **Instant setup**: `g i` - initialize repos in a flash
|
|
34
47
|
|
|
35
|
-
|
|
48
|
+
### 🧠 **Intelligent Code Analysis**
|
|
49
|
+
- Analyzes actual code changes, not just file names
|
|
50
|
+
- Understands context from function changes, imports, and logic
|
|
51
|
+
- Handles everything from bug fixes to feature additions
|
|
52
|
+
- Graceful fallbacks for extremely large changesets
|
|
53
|
+
|
|
54
|
+
### 🛠️ **Developer-Friendly**
|
|
55
|
+
- **Numbered commit history**: Easy navigation with `g ls`
|
|
56
|
+
- **Smart branching**: `g b 5` creates branch from commit #5
|
|
57
|
+
- **Safe operations**: Built-in error handling and validation
|
|
58
|
+
- **Clean interface**: Intuitive commands that just make sense
|
|
36
59
|
|
|
37
|
-
##
|
|
60
|
+
## 🚀 Quick Start
|
|
38
61
|
|
|
39
|
-
###
|
|
62
|
+
### Installation
|
|
40
63
|
|
|
41
64
|
```bash
|
|
42
|
-
|
|
65
|
+
npm install -g gims
|
|
43
66
|
```
|
|
44
67
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
### 2. Commit & Push with AI Message
|
|
68
|
+
### Setup AI (Choose One)
|
|
48
69
|
|
|
70
|
+
**Option 1: OpenAI (Recommended)**
|
|
49
71
|
```bash
|
|
50
|
-
|
|
72
|
+
export OPENAI_API_KEY="your-api-key-here"
|
|
51
73
|
```
|
|
52
74
|
|
|
53
|
-
|
|
75
|
+
**Option 2: Google Gemini (Faster)**
|
|
76
|
+
```bash
|
|
77
|
+
export GEMINI_API_KEY="your-api-key-here"
|
|
78
|
+
```
|
|
54
79
|
|
|
55
|
-
|
|
80
|
+
### Your First AI Commit
|
|
56
81
|
|
|
57
|
-
|
|
82
|
+
```bash
|
|
83
|
+
# Make some changes to your code
|
|
84
|
+
echo "console.log('Hello GIMS!');" > hello.js
|
|
58
85
|
|
|
59
|
-
|
|
86
|
+
# Let AI commit it for you
|
|
87
|
+
g o
|
|
88
|
+
# Output: Committed & pushed: "Add hello world console log"
|
|
89
|
+
```
|
|
60
90
|
|
|
91
|
+
## 📖 Commands Reference
|
|
92
|
+
|
|
93
|
+
| Command | Alias | Description | Example |
|
|
94
|
+
|---------|-------|-------------|---------|
|
|
95
|
+
| `gims init` | `g i` | Initialize new Git repo | `g i` |
|
|
96
|
+
| `gims clone <repo>` | `g c` | Clone repository | `g c https://github.com/user/repo` |
|
|
97
|
+
| `gims suggest` | `g s` | Generate & copy commit message | `g s` |
|
|
98
|
+
| `gims commit` | `g cm` | Interactive commit message generation | `g cm` |
|
|
99
|
+
| `gims local` | `g l` | AI commit locally | `g l` |
|
|
100
|
+
| `gims online` | `g o` | AI commit + push | `g o` |
|
|
101
|
+
| `gims pull` | `g p` | Pull latest changes | `g p` |
|
|
102
|
+
| `gims list` | `g ls` | Show numbered commit history | `g ls` |
|
|
103
|
+
| `gims largelist` | `g ll` | Detailed commit history | `g ll` |
|
|
104
|
+
| `gims branch <n>` | `g b` | Branch from commit #n | `g b 3 feature-x` |
|
|
105
|
+
| `gims reset <n>` | `g r` | Reset to commit #n | `g r 5 --hard` |
|
|
106
|
+
| `gims revert <n>` | `g rv` | Safely revert commit #n | `g rv 2` |
|
|
107
|
+
|
|
108
|
+
## 💡 Real-World Examples
|
|
109
|
+
|
|
110
|
+
### 🔧 Bug Fix
|
|
61
111
|
```bash
|
|
62
|
-
|
|
112
|
+
# You fix a null pointer exception
|
|
113
|
+
g o
|
|
114
|
+
# AI generates: "Fix null pointer exception in user authentication"
|
|
63
115
|
```
|
|
64
116
|
|
|
65
|
-
|
|
117
|
+
### ✨ New Feature
|
|
118
|
+
```bash
|
|
119
|
+
# You add a search function
|
|
120
|
+
g o
|
|
121
|
+
# AI generates: "Add search functionality with pagination support"
|
|
122
|
+
```
|
|
66
123
|
|
|
124
|
+
### 📚 Documentation
|
|
125
|
+
```bash
|
|
126
|
+
# You update README and add comments
|
|
127
|
+
g o
|
|
128
|
+
# AI generates: "Update documentation and add inline code comments"
|
|
67
129
|
```
|
|
68
|
-
|
|
69
|
-
|
|
130
|
+
|
|
131
|
+
### 🎨 Refactoring
|
|
132
|
+
```bash
|
|
133
|
+
# You clean up code structure
|
|
134
|
+
g o
|
|
135
|
+
# AI generates: "Refactor authentication module for better maintainability"
|
|
70
136
|
```
|
|
71
137
|
|
|
72
|
-
|
|
138
|
+
## 🔥 Pro Tips
|
|
73
139
|
|
|
140
|
+
### 🎯 **Perfect Workflow**
|
|
74
141
|
```bash
|
|
75
|
-
|
|
142
|
+
# Daily development cycle
|
|
143
|
+
g p # Pull latest changes
|
|
144
|
+
# ... code your features ...
|
|
145
|
+
g s # Preview AI suggestion
|
|
146
|
+
g l # Commit locally first
|
|
147
|
+
# ... test your changes ...
|
|
148
|
+
g o # Push with AI commit message
|
|
76
149
|
```
|
|
77
150
|
|
|
78
|
-
|
|
151
|
+
### 🧠 **Smart Branching**
|
|
152
|
+
```bash
|
|
153
|
+
g ls # See numbered history
|
|
154
|
+
g b 5 hotfix # Branch from commit #5
|
|
155
|
+
g l # Make changes and commit
|
|
156
|
+
g checkout main && g pull # Back to main
|
|
157
|
+
```
|
|
79
158
|
|
|
80
|
-
|
|
159
|
+
### 🛡️ **Safe Experimentation**
|
|
160
|
+
```bash
|
|
161
|
+
g l # Commit your experiment
|
|
162
|
+
# ... code breaks something ...
|
|
163
|
+
g r 1 --soft # Soft reset to previous commit
|
|
164
|
+
# ... fix and try again ...
|
|
165
|
+
```
|
|
81
166
|
|
|
82
|
-
##
|
|
167
|
+
## ⚙️ Configuration
|
|
83
168
|
|
|
84
|
-
###
|
|
169
|
+
### Environment Variables
|
|
85
170
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
171
|
+
| Variable | Purpose | Required |
|
|
172
|
+
|----------|---------|----------|
|
|
173
|
+
| `OPENAI_API_KEY` | OpenAI API access | One of these |
|
|
174
|
+
| `GEMINI_API_KEY` | Google Gemini API access | One of these |
|
|
89
175
|
|
|
90
|
-
|
|
176
|
+
### Smart Fallbacks
|
|
91
177
|
|
|
92
|
-
|
|
178
|
+
GIMS handles edge cases gracefully:
|
|
93
179
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
180
|
+
- **🔄 Large diffs**: Automatically switches to file summary mode
|
|
181
|
+
- **📊 Massive changes**: Falls back to status-based analysis
|
|
182
|
+
- **🛜 No API key**: Uses sensible default messages
|
|
183
|
+
- **⚠️ API failures**: Graceful degradation with helpful errors
|
|
184
|
+
- **🪙 Token limits**: Intelligent content chunking with 100K token limit
|
|
97
185
|
|
|
98
|
-
|
|
186
|
+
## 🤝 Contributing
|
|
99
187
|
|
|
100
|
-
|
|
188
|
+
We love contributions! Here's how to get involved:
|
|
101
189
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
190
|
+
1. **🍴 Fork** the repository
|
|
191
|
+
2. **🌿 Create** your feature branch: `git checkout -b amazing-feature`
|
|
192
|
+
3. **💻 Code** your improvements
|
|
193
|
+
4. **🧪 Test** thoroughly
|
|
194
|
+
5. **📝 Commit** with GIMS: `g l` (dogfooding!)
|
|
195
|
+
6. **🚀 Push** and create a Pull Request
|
|
105
196
|
|
|
106
|
-
|
|
197
|
+
### 🐛 Found a Bug?
|
|
107
198
|
|
|
108
|
-
|
|
199
|
+
1. Check [existing issues](https://github.com/s41r4j/gims/issues)
|
|
200
|
+
2. Create a [new issue](https://github.com/s41r4j/gims/issues/new) with:
|
|
201
|
+
- Clear description
|
|
202
|
+
- Steps to reproduce
|
|
203
|
+
- Expected vs actual behavior
|
|
204
|
+
- Your environment details
|
|
109
205
|
|
|
110
|
-
##
|
|
206
|
+
## 📊 Why GIMS?
|
|
111
207
|
|
|
208
|
+
### Before GIMS 😫
|
|
112
209
|
```bash
|
|
113
|
-
|
|
210
|
+
git log --oneline
|
|
211
|
+
abc1234 fix
|
|
212
|
+
def5678 update
|
|
213
|
+
ghi9012 changes
|
|
214
|
+
jkl3456 stuff
|
|
215
|
+
mno7890 final fix
|
|
114
216
|
```
|
|
115
217
|
|
|
116
|
-
|
|
218
|
+
### After GIMS ✨
|
|
219
|
+
```bash
|
|
220
|
+
git log --oneline
|
|
221
|
+
abc1234 Fix authentication timeout in user login service
|
|
222
|
+
def5678 Add responsive design for mobile navigation menu
|
|
223
|
+
ghi9012 Refactor database connection pool for better performance
|
|
224
|
+
jkl3456 Update API documentation with new endpoint examples
|
|
225
|
+
mno7890 Fix memory leak in image processing pipeline
|
|
226
|
+
```
|
|
117
227
|
|
|
118
|
-
|
|
228
|
+
## 📈 Stats
|
|
119
229
|
|
|
120
|
-
|
|
230
|
+
- ⚡ **10x faster** commits than traditional Git workflow
|
|
231
|
+
- 🎯 **95%+ accuracy** in commit message relevance
|
|
232
|
+
- 📚 **Zero learning curve** - if you know Git, you know GIMS
|
|
233
|
+
- 🌍 **Works everywhere** - Mac, Windows, Linux, WSL
|
|
121
234
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
235
|
+
## 🗺️ Roadmap
|
|
236
|
+
|
|
237
|
+
- [ ] 🔌 Plugin system for custom AI providers
|
|
238
|
+
- [ ] 📊 Commit message templates and customization
|
|
239
|
+
- [ ] 🌐 Multi-language commit message support
|
|
240
|
+
- [ ] 🔄 Integration with popular Git GUIs
|
|
241
|
+
- [ ] 📱 Mobile companion app
|
|
242
|
+
|
|
243
|
+
## 📄 License
|
|
244
|
+
|
|
245
|
+
MIT © [GIMS](https://github.com/s41r4j/gims)
|
|
130
246
|
|
|
131
247
|
---
|
|
132
248
|
|
|
133
|
-
|
|
249
|
+
<div align="center">
|
|
250
|
+
|
|
251
|
+
**⭐ Star this repo if GIMS makes your Git workflow awesome!**
|
|
134
252
|
|
|
135
|
-
|
|
136
|
-
* [`openai`](https://www.npmjs.com/package/openai) – OpenAI SDK
|
|
137
|
-
* [`@google-ai/gemini`](https://www.npmjs.com/package/@google-ai/gemini) – Gemini SDK
|
|
138
|
-
* [`commander`](https://www.npmjs.com/package/commander) – CLI argument parser
|
|
253
|
+
[Report Bug](https://github.com/s41r4j/gims/issues) • [Request Feature](https://github.com/s41r4j/gims/issues) • [Documentation](https://github.com/s41r4j/gims#readme)
|
|
139
254
|
|
|
255
|
+
*Made with ❤️ by developers who hate writing commit messages*
|
|
140
256
|
|
|
257
|
+
</div>
|
package/bin/gims.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
const { Command } = require('commander');
|
|
7
7
|
const simpleGit = require('simple-git');
|
|
8
|
-
const clipboard = require('clipboardy');
|
|
9
8
|
const process = require('process');
|
|
10
9
|
const { OpenAI } = require('openai');
|
|
11
10
|
const { GoogleGenAI } = require('@google/genai');
|
|
@@ -116,6 +115,11 @@ async function generateCommitMessage(rawDiff) {
|
|
|
116
115
|
return 'Update multiple files';
|
|
117
116
|
}
|
|
118
117
|
|
|
118
|
+
// Check if API key is available
|
|
119
|
+
if (!process.env.GEMINI_API_KEY && !process.env.OPENAI_API_KEY) {
|
|
120
|
+
return null; // Signal that no API key is available
|
|
121
|
+
}
|
|
122
|
+
|
|
119
123
|
let message = 'Update project code'; // Default fallback
|
|
120
124
|
|
|
121
125
|
try {
|
|
@@ -125,13 +129,13 @@ async function generateCommitMessage(rawDiff) {
|
|
|
125
129
|
model: 'gemini-2.0-flash',
|
|
126
130
|
contents: prompt
|
|
127
131
|
});
|
|
128
|
-
message =
|
|
132
|
+
message = res.text.trim();
|
|
129
133
|
} else if (process.env.OPENAI_API_KEY) {
|
|
130
134
|
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
|
|
131
135
|
const res = await openai.chat.completions.create({
|
|
132
136
|
model: 'gpt-4o-mini',
|
|
133
137
|
messages: [{ role: 'user', content: prompt }],
|
|
134
|
-
temperature: 0.
|
|
138
|
+
temperature: 0.75,
|
|
135
139
|
max_tokens: 100 // Limit response length
|
|
136
140
|
});
|
|
137
141
|
message = res.choices[0].message.content.trim();
|
|
@@ -176,7 +180,7 @@ program.command('clone <repo>').alias('c')
|
|
|
176
180
|
});
|
|
177
181
|
|
|
178
182
|
program.command('suggest').alias('s')
|
|
179
|
-
.description('Suggest commit message
|
|
183
|
+
.description('Suggest commit message')
|
|
180
184
|
.action(async () => {
|
|
181
185
|
if (!(await hasChanges())) {
|
|
182
186
|
return console.log('No changes to suggest.');
|
|
@@ -185,23 +189,92 @@ program.command('suggest').alias('s')
|
|
|
185
189
|
const { all } = await safeLog();
|
|
186
190
|
const isFirst = all.length === 0;
|
|
187
191
|
|
|
188
|
-
//
|
|
189
|
-
await git.
|
|
190
|
-
|
|
191
|
-
// Get the appropriate diff
|
|
192
|
-
const rawDiff = await git.diff(['--cached']);
|
|
192
|
+
// Get diff of unstaged changes
|
|
193
|
+
let rawDiff = await git.diff();
|
|
193
194
|
|
|
195
|
+
// If no diff from tracked files, check for untracked files
|
|
194
196
|
if (!rawDiff.trim()) {
|
|
195
|
-
|
|
197
|
+
const status = await git.status();
|
|
198
|
+
if (status.not_added.length > 0) {
|
|
199
|
+
// For untracked files, show file list since we can't diff them
|
|
200
|
+
rawDiff = `New files:\n${status.not_added.join('\n')}`;
|
|
201
|
+
} else {
|
|
202
|
+
return console.log('No changes to suggest.');
|
|
203
|
+
}
|
|
196
204
|
}
|
|
197
205
|
|
|
198
206
|
const msg = await generateCommitMessage(rawDiff);
|
|
199
207
|
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
208
|
+
if (msg === null) {
|
|
209
|
+
return console.log('Please set GEMINI_API_KEY or OPENAI_API_KEY environment variable');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
console.log(`git add . && git commit -m "${msg}"`);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
program.command('commit').alias('cm')
|
|
216
|
+
.description('Interactive commit message generation')
|
|
217
|
+
.action(async () => {
|
|
218
|
+
if (!(await hasChanges())) {
|
|
219
|
+
return console.log('No changes to commit.');
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// Get diff for message generation
|
|
223
|
+
let rawDiff = await git.diff();
|
|
224
|
+
|
|
225
|
+
// If no diff from tracked files, check for untracked files
|
|
226
|
+
if (!rawDiff.trim()) {
|
|
227
|
+
const status = await git.status();
|
|
228
|
+
if (status.not_added.length > 0) {
|
|
229
|
+
rawDiff = `New files:\n${status.not_added.join('\n')}`;
|
|
230
|
+
} else {
|
|
231
|
+
return console.log('No changes to commit.');
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (!process.env.GEMINI_API_KEY && !process.env.OPENAI_API_KEY) {
|
|
236
|
+
return console.log('Please set GEMINI_API_KEY or OPENAI_API_KEY environment variable');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
const readline = require('readline');
|
|
240
|
+
const rl = readline.createInterface({
|
|
241
|
+
input: process.stdin,
|
|
242
|
+
output: process.stdout
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
const askForInput = () => {
|
|
246
|
+
return new Promise((resolve) => {
|
|
247
|
+
rl.question('> ', (answer) => {
|
|
248
|
+
resolve(answer.toLowerCase().trim());
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
let currentMessage = await generateCommitMessage(rawDiff);
|
|
254
|
+
console.log(`\n=== Interactive Commit ===`);
|
|
255
|
+
console.log(`┌──────────────────────────────────────────────────────────────────────┐`);
|
|
256
|
+
console.log(`│ Press "Enter" to generate new message, "c" to commit, or "q" to quit │`);
|
|
257
|
+
console.log(`└──────────────────────────────────────────────────────────────────────┘\n`);
|
|
258
|
+
console.log(`Suggested: "${currentMessage}"`);
|
|
259
|
+
|
|
260
|
+
while (true) {
|
|
261
|
+
const input = await askForInput();
|
|
262
|
+
|
|
263
|
+
if (input === 'q' || input === 'quit') {
|
|
264
|
+
console.log('Cancelled.');
|
|
265
|
+
rl.close();
|
|
266
|
+
return;
|
|
267
|
+
} else if (input === 'c' || input === 'commit') {
|
|
268
|
+
await git.add('.');
|
|
269
|
+
await git.commit(currentMessage);
|
|
270
|
+
console.log(`Committed: "${currentMessage}"`);
|
|
271
|
+
rl.close();
|
|
272
|
+
return;
|
|
273
|
+
} else {
|
|
274
|
+
// Generate new message
|
|
275
|
+
currentMessage = await generateCommitMessage(rawDiff);
|
|
276
|
+
console.log(`Suggested: "${currentMessage}"`);
|
|
277
|
+
}
|
|
205
278
|
}
|
|
206
279
|
});
|
|
207
280
|
|
|
@@ -226,6 +299,11 @@ program.command('local').alias('l')
|
|
|
226
299
|
}
|
|
227
300
|
|
|
228
301
|
const msg = await generateCommitMessage(rawDiff);
|
|
302
|
+
|
|
303
|
+
if (msg === null) {
|
|
304
|
+
return console.log('Please set GEMINI_API_KEY or OPENAI_API_KEY environment variable');
|
|
305
|
+
}
|
|
306
|
+
|
|
229
307
|
await git.commit(msg);
|
|
230
308
|
console.log(`Committed locally: "${msg}"`);
|
|
231
309
|
});
|
|
@@ -251,6 +329,11 @@ program.command('online').alias('o')
|
|
|
251
329
|
}
|
|
252
330
|
|
|
253
331
|
const msg = await generateCommitMessage(rawDiff);
|
|
332
|
+
|
|
333
|
+
if (msg === null) {
|
|
334
|
+
return console.log('Please set GEMINI_API_KEY or OPENAI_API_KEY environment variable');
|
|
335
|
+
}
|
|
336
|
+
|
|
254
337
|
await git.commit(msg);
|
|
255
338
|
await git.push();
|
|
256
339
|
console.log(`Committed & pushed: "${msg}"`);
|
|
@@ -302,4 +385,4 @@ program.command('revert <c>').alias('rv')
|
|
|
302
385
|
catch (e) { console.error('Revert error:', e.message); }
|
|
303
386
|
});
|
|
304
387
|
|
|
305
|
-
program.parse(process.argv);
|
|
388
|
+
program.parse(process.argv);
|