commitgpt 0.2.0 → 0.3.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 550cd13670cec1d792df268d54b8c511ca528bb498377a9789bb265acb8a55a5
4
- data.tar.gz: 6cbf6bb2c24376cca893409b6af23879225e61c02111c2cba656eac361b60da9
3
+ metadata.gz: 39ba14207dd3a3821b77597f628a3a5eb5c4d350bac6f5aac1828feda130f7df
4
+ data.tar.gz: d03c824c7e5f6b31a3e16dc1175def59b85980da67e9767a643242ea5d65b1df
5
5
  SHA512:
6
- metadata.gz: e835710e43929f73e491ec963c37e37763f0d620e5711d746db4ea066110e012edbeef6ff8d2dd849e0dcd443a131dfcb31654aeb2438f7386e2d4568ec80fba
7
- data.tar.gz: 34c20bf93a7fe6553b74706fb32b7be50c875471a535d1abebaffd768dd14ddfb235dc58887b5028f500e65a560486aa8309e87c93e4424a3ee86c76fd04b876
6
+ metadata.gz: 84fed7c25c40981c4ac1c6d29e26c5260b3b79a59e7e7921aec5d0f176d826f07c06d21d354fd7168d3b0a0f17a9bcd834271d17cd5a2db0cf63964de02a4dd0
7
+ data.tar.gz: e443c012f0ddb35f03551a4d7b943dd207c5500f647e6cacf429f20e3ce1e6863eced86f9292232c7ce49a6aa6fb2d088e180d3c59b8bc268e24fd07d980b097
data/README.md CHANGED
@@ -8,128 +8,266 @@
8
8
  ---
9
9
 
10
10
  ## Installation
11
+
12
+ ### Method 1: Homebrew (Recommended)
13
+
14
+ The easiest way to install and keep CommitGPT updated.
15
+
16
+ **Install:**
17
+
11
18
  ```bash
12
- $ gem install commitgpt
19
+ brew tap ZPVIP/commitgpt https://github.com/ZPVIP/commitgpt
20
+ brew install commitgpt
13
21
  ```
14
22
 
15
- ## Usage
23
+ **Upgrade:**
16
24
 
17
- ### API Key
18
- Grab your API key and add it as an env variable.
19
25
  ```bash
20
- $ export AICM_KEY=sk-xxxxxxxxxxxxxxxx
26
+ brew update
27
+ brew upgrade commitgpt
21
28
  ```
22
29
 
23
- It's recommended to add this to your `.zshrc` or `.bashrc` so it persists across terminal sessions.
30
+ **Uninstall:**
31
+
32
+ ```bash
33
+ brew uninstall commitgpt
34
+ # Optional: Remove configuration files manually
35
+ rm -rf ~/.config/commitgpt
36
+ ```
37
+
38
+ ### Method 2: RubyGems (For Ruby Developers)
39
+
40
+ <details>
41
+ <summary>Click to expand RubyGems installation instructions</summary>
42
+
43
+ #### Prerequisites: Install Ruby
44
+
45
+ If you don't have Ruby installed, follow these steps first.
46
+
47
+ <details>
48
+ <summary><strong>macOS</strong></summary>
49
+
50
+ **1. Install Homebrew** (skip if already installed)
24
51
 
25
- ### Custom API Endpoint (Optional)
26
- You can use any OpenAI-compatible API provider by setting `AICM_LINK`:
27
52
  ```bash
28
- # Use a local proxy
29
- $ export AICM_LINK=http://127.0.0.1:8045/v1
53
+ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
54
+ echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
55
+ source ~/.zshrc
56
+ ```
30
57
 
31
- # Or use another provider
32
- # Cerebras
33
- $ export AICM_LINK=https://api.cerebras.ai/v1
58
+ **2. Install Ruby dependencies**
34
59
 
35
- # Groq
36
- $ export AICM_LINK=https://api.groq.com/openai/v1
60
+ ```bash
61
+ brew install openssl@3 libyaml gmp rust
37
62
  ```
38
63
 
39
- > **Note**: If you're using a local proxy that doesn't require authentication, you can leave `AICM_KEY` empty.
64
+ </details>
65
+
66
+ <details>
67
+ <summary><strong>Ubuntu / Debian</strong></summary>
68
+
69
+ **Install Ruby dependencies**
40
70
 
41
- ### List Models
42
- Use `-m` to list all available models from your API provider:
43
71
  ```bash
44
- $ aicm -m
45
- llama3.1-8b
46
- llama-3.3-70b
47
- gpt-4o-mini
72
+ sudo apt-get update
73
+ sudo apt install build-essential rustc libssl-dev libyaml-dev zlib1g-dev libgmp-dev
74
+ ```
75
+
76
+ </details>
77
+
78
+ **Install Ruby with Mise** (version manager)
79
+
80
+ ```bash
81
+ # Install Mise
82
+ curl https://mise.run | sh
83
+
84
+ # For zsh (macOS default)
85
+ echo 'eval "$(~/.local/bin/mise activate)"' >> ~/.zshrc
86
+ source ~/.zshrc
87
+
88
+ # For bash (Ubuntu default)
89
+ # echo 'eval "$(~/.local/bin/mise activate)"' >> ~/.bashrc
90
+ # source ~/.bashrc
91
+
92
+ # Install Ruby
93
+ mise use --global ruby@3
94
+
95
+ # Verify installation
96
+ ruby --version
97
+ #=> 3.4.7
98
+
99
+ # Update RubyGems
100
+ gem update --system
101
+ ```
102
+
103
+ #### Install CommitGPT
104
+
105
+ ```bash
106
+ gem install commitgpt
107
+ ```
108
+
109
+ </details>
110
+
111
+ ---
112
+
113
+ ## Configuration
114
+
115
+ CommitGPT uses a YAML configuration system (`~/.config/commitgpt/`) to support multiple providers and per-provider settings.
116
+
117
+ ### Interactive Setup (Recommended)
118
+ Run the setup wizard to configure your provider:
119
+ ```bash
120
+ $ aicm setup
48
121
  ```
49
122
 
50
- ### aicm
51
- `aicm` is an abbreviation for `AI commits`. After staging your changes with `git add .`, use `aicm` to commit with an AI-generated message.
123
+ You'll be guided to:
124
+ 1. Choose an AI provider (Presets: Cerebras, OpenAI, Ollama, Groq, etc.)
125
+ 2. Enter your API Key (stored securely in `config.local.yml`)
126
+ 3. Select a model interactively
127
+ 4. Set maximum diff length
128
+
129
+ **Note:** Please add `~/.config/commitgpt/config.local.yml` to your `.gitignore` if you are syncing your home directory, as it contains your API keys.
130
+
131
+ ---
132
+
133
+ ## Usage
134
+
135
+ ### Generate Commit Message
136
+ Stage your changes and run `aicm`:
52
137
  ```bash
53
- $ cd /path/to/your/repo
54
138
  $ git add .
55
139
  $ aicm
140
+ ```
141
+
142
+ ### Switch Provider
143
+ Switch between configured providers easily:
144
+ ```bash
145
+ $ aicm -p
146
+ # or
147
+ $ aicm --provider
148
+ ```
56
149
 
57
- Welcome to AI Commits!
58
- ▲ Generating your AI commit message...
150
+ ### Select Model
151
+ Interactively list and select a model for your current provider:
152
+ ```bash
153
+ $ aicm -m
154
+ # or
155
+ $ aicm --models
156
+ ```
59
157
 
60
- Commit message: git commit -am "Update README.md with contribution instructions and OpenAI API key instructions."
158
+ ### Check Configuration
159
+ View your current configuration (Provider, Model, Base URL, Diff Len):
160
+ ```bash
161
+ $ aicm help
162
+ ```
163
+ (Use the help command to see current active provider settings)
61
164
 
62
- Do you want to commit this message? [y/n]
63
- [main c082637] Update README.md with contribution instructions and OpenAI API key instructions.
64
- 4 files changed, 24 insertions(+), 19 deletions(-)
165
+ ### View Git Diff
166
+ Preview the diff that will be sent to the AI:
167
+ ```bash
168
+ $ aicm -v
65
169
  ```
66
170
 
67
171
  ### Update
68
- To update to the latest version:
172
+ To update to the latest version (if installed via Gem):
69
173
  ```bash
70
174
  $ gem update commitgpt
71
- $ gem cleanup commitgpt
72
- $ gem info commitgpt
73
175
  ```
74
176
 
75
- ## Configuration
76
-
77
- | Environment Variable | Required | Default | Description |
78
- |---------------------|----------|---------|-------------|
79
- | `AICM_KEY` | No* | `nil` | Your API key. Required when using official OpenAI API. |
80
- | `AICM_LINK` | No | `https://api.openai.com/v1` | Custom API endpoint for OpenAI-compatible services. |
81
- | `AICM_MODEL` | Yes | `gpt-4o-mini` | Model to use for generating commit messages. |
82
- | `AICM_DIFF_LEN` | No | `32768` | Maximum diff length in characters. Increase if you have large diffs. |
83
-
84
- \* Required when using the default OpenAI endpoint.
177
+ ---
85
178
 
86
- ### Available Models
179
+ ## Supported Providers
180
+ We support any OpenAI-compatible API. Presets available for:
181
+ - **Cerebras** (Fast & Recommended)
182
+ - **OpenAI** (Official)
183
+ - **Ollama** (Local)
184
+ - **Groq**
185
+ - **DeepSeek**
186
+ - **Anthropic (Claude)**
187
+ - **Google AI (Gemini)**
188
+ - **Mistral**
189
+ - **OpenRouter**
190
+ - **Local setups** (LM Studio, LLaMa.cpp, Llamafile)
87
191
 
88
- Use `aicm -m` to list models from your provider, or set `AICM_MODEL` directly:
192
+ ### Recommended Providers
89
193
 
90
- **OpenAI** ([https://api.openai.com/v1](https://platform.openai.com))
194
+ **OpenAI** ([https://platform.openai.com](https://platform.openai.com))
91
195
  ```
92
- gpt-5.2
93
- gpt-5-mini
94
- gpt-5-nano
196
+ gpt-4o
95
197
  gpt-4o-mini
96
198
  ```
97
199
 
98
- **Cerebras** ([https://api.cerebras.ai/v1](https://cloud.cerebras.ai))
200
+ **Cerebras** ([https://cloud.cerebras.ai](https://cloud.cerebras.ai)) ⭐ Recommended
99
201
  ```
100
- zai-glm-4.6
101
- zai-glm-4.7
102
- gpt-oss-120b
202
+ zai-glm-4.7 # ⭐ Best for commit messages - fast & accurate
103
203
  llama3.1-8b
104
204
  llama-3.3-70b
105
- qwen-3-32b
106
- qwen-3-235b-a22b-instruct-2507
107
-
108
205
  ```
109
206
 
110
- **Groq** ([https://api.groq.com/openai/v1](https://console.groq.com))
207
+ **Groq** ([https://console.groq.com](https://console.groq.com))
111
208
  ```
112
209
  llama-3.3-70b-versatile
113
210
  llama-3.1-8b-instant
114
- meta-llama/llama-4-maverick-17b-128e-instruct
115
- meta-llama/llama-4-scout-17b-16e-instruct
116
- qwen/qwen3-32b
117
- moonshotai/kimi-k2-instruct-0905
118
- openai/gpt-oss-120b
119
- groq/compound
120
- groq/compound-mini
121
211
  ```
122
212
 
123
213
  ## How It Works
124
- This CLI tool runs a `git diff` command to grab all staged changes, sends this to OpenAI's GPT API (or compatible endpoint), and returns an AI-generated commit message. The tool uses the `/v1/chat/completions` endpoint with optimized prompts for generating conventional commit messages.
125
-
126
- ## Limitations
127
- - Only supports git diffs up to `AICM_DIFF_LEN` characters (default 32K)
128
- - The generated commit message can't be edited interactively, but you can choose `n` and copy the command to edit manually
214
+ This CLI tool runs a `git diff` command to grab all staged changes, sends this to OpenAI's GPT API (or compatible endpoint), and returns an AI-generated commit message. The tool uses the `/v1/chat/completions` endpoint with optimized prompts/system instructions for generating conventional commit messages.
129
215
 
130
216
  ## Special Thanks
131
217
  I used ChatGPT to convert `AICommits` from TypeScript to Ruby. Special thanks to [https://github.com/Nutlope/aicommits](https://github.com/Nutlope/aicommits)
132
218
 
219
+ ---
220
+
221
+ ## Development Guide
222
+
223
+ ### Requirements
224
+ - Ruby >= 2.6.0
225
+ - Git
226
+
227
+ ### Local Setup
228
+ 1. Clone the repository:
229
+ ```bash
230
+ git clone https://github.com/ZPVIP/commitgpt.git
231
+ cd commitgpt
232
+ ```
233
+ 2. Install dependencies:
234
+ ```bash
235
+ bundle install
236
+ ```
237
+
238
+ ### Local Build and Install
239
+ To test your changes locally (builds the gem and installs it to your system):
240
+ ```bash
241
+ gem build commitgpt.gemspec
242
+ gem install ./commitgpt-*.gem
243
+ ```
244
+
245
+ ### Publishing
246
+
247
+ #### RubyGems
248
+ To publish a new version to RubyGems.org (requires RubyGems account permissions):
249
+ ```bash
250
+ gem push commitgpt-*.gem
251
+ ```
252
+
253
+ #### Homebrew (GitHub Distribution)
254
+ We use a custom script to automate the GitHub Release and Homebrew Formula update process. This enables users to install via `brew tap`.
255
+
256
+ **Steps:**
257
+ ```bash
258
+ ./scripts/release.sh <version>
259
+ # Example: ./scripts/release.sh 0.3.1
260
+ ```
261
+
262
+ **This script automates:**
263
+ 1. Creating and pushing a Git Tag.
264
+ 2. Creating a GitHub Release (which generates the source tarball).
265
+ 3. Calculating the SHA256 checksum of the tarball.
266
+ 4. Updating `Formula/commitgpt.rb` with the new URL and checksum.
267
+ 5. Committing and pushing the updated Formula to the repository.
268
+
269
+ ---
270
+
133
271
  ## Contributing
134
272
  Bug reports and pull requests are welcome on GitHub at https://github.com/ZPVIP/commitgpt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ZPVIP/commitgpt/blob/main/CODE_OF_CONDUCT.md).
135
273
 
data/commitgpt.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/commitgpt/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "commitgpt"
7
+ spec.version = CommitGpt::VERSION
8
+ spec.authors = ["Peng Zhang"]
9
+ spec.email = ["zpregister@gmail.com"]
10
+
11
+ spec.summary = "A CLI AI that writes git commit messages for you."
12
+ spec.description = "A CLI that writes your git commit messages for you with AI. Never write a commit message again."
13
+ spec.homepage = "https://github.com/ZPVIP/commitgpt"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 2.6.0"
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ spec.metadata["source_code_uri"] = spec.homepage
18
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.glob("lib/**/*") + Dir.glob("bin/*") + %w[README.md LICENSE commitgpt.gemspec]
23
+ .reject { |f| File.directory?(f) }
24
+ spec.bindir = "bin"
25
+ spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+
28
+ # Uncomment to register a new dependency of your gem
29
+ spec.add_dependency "httparty", "~> 0.18"
30
+ spec.add_dependency "thor", "~> 1.2"
31
+ spec.add_dependency "tty-prompt", "~> 0.23"
32
+
33
+ # For more information and examples about making a new gem, checkout our
34
+ # guide at: https://bundler.io/guides/creating_gem.html
35
+ end
data/lib/commitgpt/cli.rb CHANGED
@@ -2,21 +2,61 @@
2
2
 
3
3
  require "thor"
4
4
  require "commitgpt/commit_ai"
5
+ require "commitgpt/setup_wizard"
5
6
 
6
7
  module CommitGpt
7
8
  # CommitGpt CLI
8
9
  class CLI < Thor
9
- default_task :aicm
10
+ default_task :generate
10
11
 
11
- desc "aicm", "AI commits for you!"
12
- method_option :models, aliases: "-m", type: :boolean, desc: "List available models"
12
+ desc "generate", "AI commits for you!"
13
+ method_option :models, aliases: "-m", type: :boolean, desc: "List/Select available models"
13
14
  method_option :verbose, aliases: "-v", type: :boolean, desc: "Show git diff being sent to AI"
14
- def aicm
15
- if options[:models]
16
- CommitGpt::CommitAi.new.list_models
15
+ method_option :provider, aliases: "-p", type: :boolean, desc: "Switch active provider"
16
+ def generate
17
+ if options[:provider]
18
+ CommitGpt::SetupWizard.new.switch_provider
19
+ elsif options[:models]
20
+ CommitGpt::SetupWizard.new.change_model
17
21
  else
18
22
  CommitGpt::CommitAi.new.aicm(verbose: options[:verbose])
19
23
  end
20
24
  end
25
+
26
+ desc "setup", "Configure AI provider and settings"
27
+ def setup
28
+ CommitGpt::SetupWizard.new.run
29
+ end
30
+
31
+ # Custom help message
32
+ def self.help(shell, subcommand = false)
33
+ shell.say "Usage:"
34
+ shell.say " aicm # Generate AI commit message (Default)"
35
+ shell.say " aicm setup # Configure AI provider and settings"
36
+ shell.say " aicm help [COMMAND] # Describe available commands"
37
+ shell.say ""
38
+ shell.say "Options:"
39
+ shell.say " -m, --models # Interactive model selection"
40
+ shell.say " -p, --provider # Switch active provider"
41
+ shell.say " -v, --verbose # Show git diff being sent to AI"
42
+ shell.say ""
43
+
44
+ # Show current configuration
45
+ begin
46
+ require "commitgpt/config_manager"
47
+ require "commitgpt/string"
48
+ config = CommitGpt::ConfigManager.get_active_provider_config
49
+ if config
50
+ shell.say "Current Configuration:"
51
+ shell.say " Provider: #{config['name'].green}"
52
+ shell.say " Model: #{config['model'].cyan}"
53
+ shell.say " Base URL: #{config['base_url']}"
54
+ shell.say " Diff Len: #{config['diff_len']}"
55
+ shell.say ""
56
+ end
57
+ rescue StandardError
58
+ # Ignore errors during help display if config is missing/invalid
59
+ end
60
+ end
21
61
  end
22
62
  end