aigcm 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 +4 -4
- data/CHANGELOG.md +16 -0
- data/COMMITS.md +196 -0
- data/README.md +91 -19
- data/bin/aigcm +3 -1
- data/lib/aigcm/commit_message_generator.rb +47 -13
- data/lib/aigcm/options.rb +58 -0
- data/lib/aigcm/style_guide.rb +2 -2
- data/lib/aigcm/version.rb +1 -1
- data/lib/aigcm.rb +79 -107
- metadata +30 -17
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2cc53c8ffef5c597adb196deffc67ad3c0f89d5a47e9bcbfc617ece6f6a73600
|
|
4
|
+
data.tar.gz: 6262260bc17b80ef51b668e19a7014c8e9cd4429f22f2654b8682303fb79ea39
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c5b256a8478183fd3bd53188916e36f2e48639927251ea128111f28baf0dc42910ba7104f95d9a8fd98f6f2df804ea9403eb6c8c1f179b22b1f1675979ed2e15
|
|
7
|
+
data.tar.gz: 063a9e30564ad0b791ea9707e2e57c333d9372330e4784cc4858431725ac6f0184ffa6a331cdb8651d97e50fe2d0a4e363a83cea7d96e9577251c30761069055
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,22 @@
|
|
|
2
2
|
|
|
3
3
|
## [Unreleased]
|
|
4
4
|
|
|
5
|
+
## [0.3.0] - 2025-12-03
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
- Added missing `amend:` parameter to `GitDiff.initialize`
|
|
9
|
+
- Fixed `check_recent_commit` method signature (was receiving 2 arguments but only accepted 1)
|
|
10
|
+
- Fixed `CommitMessageGenerator.initialize` to accept required `model:`, `provider:`, and `amend:` parameters
|
|
11
|
+
- Removed dependency on `Aigcm.amend?` from `CommitMessageGenerator#generate` in favor of instance variable
|
|
12
|
+
- Added `debug_me` as development dependency
|
|
13
|
+
- Added `bundler/setup` to bin/aigcm for proper gem version loading
|
|
14
|
+
- Fixed test mocks for `GitDiff` in commit message generator tests
|
|
15
|
+
|
|
16
|
+
## [0.2.0] - 2025-02-09
|
|
17
|
+
|
|
18
|
+
- changed gem name to aigcm
|
|
19
|
+
- released gem
|
|
20
|
+
|
|
5
21
|
## [0.1.0] - 2025-02-08
|
|
6
22
|
|
|
7
23
|
- changed gem name to aigc
|
data/COMMITS.md
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
---
|
|
2
|
+
url: https://www.conventionalcommits.org/en/v1.0.0/
|
|
3
|
+
title: Conventional Commits
|
|
4
|
+
description: A specification for adding human and machine readable meaning to commit messages
|
|
5
|
+
access_date: 2025-07-31T20:51:29.000Z
|
|
6
|
+
current_date: 2025-07-31T20:51:29.601Z
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Conventional Commits
|
|
10
|
+
|
|
11
|
+
A specification for adding human and machine readable meaning to commit messages
|
|
12
|
+
|
|
13
|
+
Quick Summary Full Specification Contribute
|
|
14
|
+
|
|
15
|
+
# Conventional Commits 1.0.0
|
|
16
|
+
|
|
17
|
+
## Summary
|
|
18
|
+
|
|
19
|
+
The Conventional Commits specification is a lightweight convention on top of commit messages. It provides an easy set of rules for creating an explicit commit history; which makes it easier to write automated tools on top of. This convention dovetails with SemVer, by describing the features, fixes, and breaking changes made in commit messages.
|
|
20
|
+
|
|
21
|
+
The commit message should be structured as follows:
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
```
|
|
26
|
+
<type>[optional scope]: <description>
|
|
27
|
+
|
|
28
|
+
[optional body]
|
|
29
|
+
|
|
30
|
+
[optional footer(s)]
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
The commit contains the following structural elements, to communicate intent to the consumers of your library:
|
|
37
|
+
|
|
38
|
+
1. **fix:** a commit of the _type_ `fix` patches a bug in your codebase (this correlates with `PATCH` in Semantic Versioning).
|
|
39
|
+
2. **feat:** a commit of the _type_ `feat` introduces a new feature to the codebase (this correlates with `MINOR` in Semantic Versioning).
|
|
40
|
+
3. **BREAKING CHANGE:** a commit that has a footer `BREAKING CHANGE:`, or appends a `!` after the type/scope, introduces a breaking API change (correlating with `MAJOR` in Semantic Versioning). A BREAKING CHANGE can be part of commits of any _type_.
|
|
41
|
+
4. _types_ other than `fix:` and `feat:` are allowed, for example @commitlint/config-conventional (based on the Angular convention) recommends `build:`, `chore:`,`ci:`, `docs:`, `style:`, `refactor:`, `perf:`, `test:`, and others.
|
|
42
|
+
5. _footers_ other than `BREAKING CHANGE: <description>` may be provided and follow a convention similar to git trailer format.
|
|
43
|
+
|
|
44
|
+
Additional types are not mandated by the Conventional Commits specification, and have no implicit effect in Semantic Versioning (unless they include a BREAKING CHANGE). A scope may be provided to a commit’s type, to provide additional contextual information and is contained within parenthesis, e.g., `feat(parser): add ability to parse arrays`.
|
|
45
|
+
|
|
46
|
+
## Examples
|
|
47
|
+
|
|
48
|
+
### Commit message with description and breaking change footer
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
feat: allow provided config object to extend other configs
|
|
52
|
+
|
|
53
|
+
BREAKING CHANGE: `extends` key in config file is now used for extending other config files
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Commit message with `!` to draw attention to breaking change
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
feat!: send an email to the customer when a product is shipped
|
|
61
|
+
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Commit message with scope and `!` to draw attention to breaking change
|
|
65
|
+
|
|
66
|
+
```
|
|
67
|
+
feat(api)!: send an email to the customer when a product is shipped
|
|
68
|
+
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
### Commit message with both `!` and BREAKING CHANGE footer
|
|
72
|
+
|
|
73
|
+
```
|
|
74
|
+
chore!: drop support for Node 6
|
|
75
|
+
|
|
76
|
+
BREAKING CHANGE: use JavaScript features not available in Node 6.
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Commit message with no body
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
docs: correct spelling of CHANGELOG
|
|
84
|
+
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Commit message with scope
|
|
88
|
+
|
|
89
|
+
```
|
|
90
|
+
feat(lang): add Polish language
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
### Commit message with multi-paragraph body and multiple footers
|
|
95
|
+
|
|
96
|
+
```
|
|
97
|
+
fix: prevent racing of requests
|
|
98
|
+
|
|
99
|
+
Introduce a request id and a reference to latest request. Dismiss
|
|
100
|
+
incoming responses other than from latest request.
|
|
101
|
+
|
|
102
|
+
Remove timeouts which were used to mitigate the racing issue but are
|
|
103
|
+
obsolete now.
|
|
104
|
+
|
|
105
|
+
Reviewed-by: Z
|
|
106
|
+
Refs: #123
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## Specification
|
|
111
|
+
|
|
112
|
+
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC 2119.
|
|
113
|
+
|
|
114
|
+
1. Commits MUST be prefixed with a type, which consists of a noun, `feat`, `fix`, etc., followed by the OPTIONAL scope, OPTIONAL `!`, and REQUIRED terminal colon and space.
|
|
115
|
+
2. The type `feat` MUST be used when a commit adds a new feature to your application or library.
|
|
116
|
+
3. The type `fix` MUST be used when a commit represents a bug fix for your application.
|
|
117
|
+
4. A scope MAY be provided after a type. A scope MUST consist of a noun describing a section of the codebase surrounded by parenthesis, e.g., `fix(parser):`
|
|
118
|
+
5. A description MUST immediately follow the colon and space after the type/scope prefix. The description is a short summary of the code changes, e.g., _fix: array parsing issue when multiple spaces were contained in string_.
|
|
119
|
+
6. A longer commit body MAY be provided after the short description, providing additional contextual information about the code changes. The body MUST begin one blank line after the description.
|
|
120
|
+
7. A commit body is free-form and MAY consist of any number of newline separated paragraphs.
|
|
121
|
+
8. One or more footers MAY be provided one blank line after the body. Each footer MUST consist of a word token, followed by either a `:<space>` or `<space>#` separator, followed by a string value (this is inspired by the git trailer convention).
|
|
122
|
+
9. A footer’s token MUST use `-` in place of whitespace characters, e.g., `Acked-by` (this helps differentiate the footer section from a multi-paragraph body). An exception is made for `BREAKING CHANGE`, which MAY also be used as a token.
|
|
123
|
+
10. A footer’s value MAY contain spaces and newlines, and parsing MUST terminate when the next valid footer token/separator pair is observed.
|
|
124
|
+
11. Breaking changes MUST be indicated in the type/scope prefix of a commit, or as an entry in the footer.
|
|
125
|
+
12. If included as a footer, a breaking change MUST consist of the uppercase text BREAKING CHANGE, followed by a colon, space, and description, e.g.,_BREAKING CHANGE: environment variables now take precedence over config files_.
|
|
126
|
+
13. If included in the type/scope prefix, breaking changes MUST be indicated by a`!` immediately before the `:`. If `!` is used, `BREAKING CHANGE:` MAY be omitted from the footer section, and the commit description SHALL be used to describe the breaking change.
|
|
127
|
+
14. Types other than `feat` and `fix` MAY be used in your commit messages, e.g., _docs: update ref docs._
|
|
128
|
+
15. The units of information that make up Conventional Commits MUST NOT be treated as case sensitive by implementors, with the exception of BREAKING CHANGE which MUST be uppercase.
|
|
129
|
+
16. BREAKING-CHANGE MUST be synonymous with BREAKING CHANGE, when used as a token in a footer.
|
|
130
|
+
|
|
131
|
+
## Why Use Conventional Commits
|
|
132
|
+
|
|
133
|
+
* Automatically generating CHANGELOGs.
|
|
134
|
+
* Automatically determining a semantic version bump (based on the types of commits landed).
|
|
135
|
+
* Communicating the nature of changes to teammates, the public, and other stakeholders.
|
|
136
|
+
* Triggering build and publish processes.
|
|
137
|
+
* Making it easier for people to contribute to your projects, by allowing them to explore a more structured commit history.
|
|
138
|
+
|
|
139
|
+
## FAQ
|
|
140
|
+
|
|
141
|
+
### How should I deal with commit messages in the initial development phase?
|
|
142
|
+
|
|
143
|
+
We recommend that you proceed as if you’ve already released the product. Typically _somebody_, even if it’s your fellow software developers, is using your software. They’ll want to know what’s fixed, what breaks etc.
|
|
144
|
+
|
|
145
|
+
### Are the types in the commit title uppercase or lowercase?
|
|
146
|
+
|
|
147
|
+
Any casing may be used, but it’s best to be consistent.
|
|
148
|
+
|
|
149
|
+
### What do I do if the commit conforms to more than one of the commit types?
|
|
150
|
+
|
|
151
|
+
Go back and make multiple commits whenever possible. Part of the benefit of Conventional Commits is its ability to drive us to make more organized commits and PRs.
|
|
152
|
+
|
|
153
|
+
### Doesn’t this discourage rapid development and fast iteration?
|
|
154
|
+
|
|
155
|
+
It discourages moving fast in a disorganized way. It helps you be able to move fast long term across multiple projects with varied contributors.
|
|
156
|
+
|
|
157
|
+
### Might Conventional Commits lead developers to limit the type of commits they make because they’ll be thinking in the types provided?
|
|
158
|
+
|
|
159
|
+
Conventional Commits encourages us to make more of certain types of commits such as fixes. Other than that, the flexibility of Conventional Commits allows your team to come up with their own types and change those types over time.
|
|
160
|
+
|
|
161
|
+
### How does this relate to SemVer?
|
|
162
|
+
|
|
163
|
+
`fix` type commits should be translated to `PATCH` releases. `feat` type commits should be translated to `MINOR` releases. Commits with `BREAKING CHANGE` in the commits, regardless of type, should be translated to `MAJOR` releases.
|
|
164
|
+
|
|
165
|
+
### How should I version my extensions to the Conventional Commits Specification, e.g. `@jameswomack/conventional-commit-spec`?
|
|
166
|
+
|
|
167
|
+
We recommend using SemVer to release your own extensions to this specification (and encourage you to make these extensions!)
|
|
168
|
+
|
|
169
|
+
### What do I do if I accidentally use the wrong commit type?
|
|
170
|
+
|
|
171
|
+
#### When you used a type that’s of the spec but not the correct type, e.g. `fix` instead of `feat`
|
|
172
|
+
|
|
173
|
+
Prior to merging or releasing the mistake, we recommend using `git rebase -i` to edit the commit history. After release, the cleanup will be different according to what tools and processes you use.
|
|
174
|
+
|
|
175
|
+
#### When you used a type _not_ of the spec, e.g. `feet` instead of `feat`
|
|
176
|
+
|
|
177
|
+
In a worst case scenario, it’s not the end of the world if a commit lands that does not meet the Conventional Commits specification. It simply means that commit will be missed by tools that are based on the spec.
|
|
178
|
+
|
|
179
|
+
### Do all my contributors need to use the Conventional Commits specification?
|
|
180
|
+
|
|
181
|
+
No! If you use a squash based workflow on Git lead maintainers can clean up the commit messages as they’re merged—adding no workload to casual committers. A common workflow for this is to have your git system automatically squash commits from a pull request and present a form for the lead maintainer to enter the proper git commit message for the merge.
|
|
182
|
+
|
|
183
|
+
### How does Conventional Commits handle revert commits?
|
|
184
|
+
|
|
185
|
+
Reverting code can be complicated: are you reverting multiple commits? if you revert a feature, should the next release instead be a patch?
|
|
186
|
+
|
|
187
|
+
Conventional Commits does not make an explicit effort to define revert behavior. Instead we leave it to tooling authors to use the flexibility of _types_ and _footers_ to develop their logic for handling reverts.
|
|
188
|
+
|
|
189
|
+
One recommendation is to use the `revert` type, and a footer that references the commit SHAs that are being reverted:
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
revert: let us never again speak of the noodle incident
|
|
193
|
+
|
|
194
|
+
Refs: 676104e, a215868
|
|
195
|
+
|
|
196
|
+
```
|
data/README.md
CHANGED
|
@@ -1,7 +1,37 @@
|
|
|
1
1
|
# aigcm
|
|
2
2
|
|
|
3
3
|
The **AI git commit message** generator.
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
See the [change log](./CHANGELOG.md) for recent changes.
|
|
6
|
+
|
|
7
|
+
<!-- Tocer[start]: Auto-generated, don't remove. -->
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
- [Overview](#overview)
|
|
12
|
+
- [Features](#features)
|
|
13
|
+
- [Installation](#installation)
|
|
14
|
+
- [Usage](#usage)
|
|
15
|
+
- [Options](#options)
|
|
16
|
+
- [Examples](#examples)
|
|
17
|
+
- [Advanced Usage](#advanced-usage)
|
|
18
|
+
- [Defaults](#defaults)
|
|
19
|
+
- [Model](#model)
|
|
20
|
+
- [Style Guide](#style-guide)
|
|
21
|
+
- [Private Repos](#private-repos)
|
|
22
|
+
- [Private Repo Check Limitation](#private-repo-check-limitation)
|
|
23
|
+
- [Style Guide Example](#style-guide-example)
|
|
24
|
+
- [API Key Configuration](#api-key-configuration)
|
|
25
|
+
- [Last Thoughts](#last-thoughts)
|
|
26
|
+
- [Support Custom Workflows](#support-custom-workflows)
|
|
27
|
+
- [Non-deterministic Nature of LLMs](#non-deterministic-nature-of-llms)
|
|
28
|
+
- [Development](#development)
|
|
29
|
+
- [Contributing](#contributing)
|
|
30
|
+
- [License](#license)
|
|
31
|
+
|
|
32
|
+
<!-- Tocer[finish]: Auto-generated, don't remove. -->
|
|
33
|
+
|
|
34
|
+
|
|
5
35
|
## Overview
|
|
6
36
|
|
|
7
37
|
**aigcm** is a Ruby gem designed to generate high-quality commit messages for git diffs. It leverages AI to analyze changes in your codebase and create concise, meaningful commit messages following best practices.
|
|
@@ -15,19 +45,7 @@ The **AI git commit message** generator.
|
|
|
15
45
|
|
|
16
46
|
## Installation
|
|
17
47
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
```ruby
|
|
21
|
-
gem 'aigcm'
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
And then execute:
|
|
25
|
-
|
|
26
|
-
```shell
|
|
27
|
-
bundle install
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
Or install it yourself as:
|
|
48
|
+
`aigcm` is a CLI tool deployed as a gem.
|
|
31
49
|
|
|
32
50
|
```shell
|
|
33
51
|
gem install aigcm
|
|
@@ -43,6 +61,7 @@ aigcm [options] [ref]
|
|
|
43
61
|
|
|
44
62
|
### Options
|
|
45
63
|
|
|
64
|
+
- `-h, --help`: Display options available.
|
|
46
65
|
- `-a, --amend`: Amend the last commit.
|
|
47
66
|
- `-c, --context=CONTEXT`: Extra context beyond the diff.
|
|
48
67
|
- `-d, --dry`: Dry run the command without making any changes.
|
|
@@ -67,21 +86,45 @@ When your commit is related to a specific JIRA ticket:
|
|
|
67
86
|
aigcm -m MODEL -c "Resolved issues as per JIRA ticket JIRA-1234"
|
|
68
87
|
```
|
|
69
88
|
|
|
70
|
-
|
|
89
|
+
Including the JIRA ticket helps relate the commit to external tracking systems.
|
|
71
90
|
|
|
72
91
|
Including multiple context strings:
|
|
73
92
|
```shell
|
|
74
93
|
aigcm -m MODEL -c "Refactored for performance" -c "JIRA-1234"
|
|
75
94
|
```
|
|
76
95
|
|
|
77
|
-
|
|
96
|
+
Multiple context strings can be added by repeating the `-c` option.
|
|
78
97
|
|
|
79
98
|
Using environment variables in context:
|
|
80
99
|
```shell
|
|
81
100
|
aigcm -c "Put the work ticket as the first entry on the subject line" -c "Ticket: $TICKET"
|
|
82
101
|
```
|
|
83
102
|
|
|
84
|
-
|
|
103
|
+
This allows you to dynamically include the value of environment variables in your commit message.
|
|
104
|
+
|
|
105
|
+
## Advanced Usage
|
|
106
|
+
|
|
107
|
+
### Defaults
|
|
108
|
+
|
|
109
|
+
There are two important defaults of which you should be aware. The model controls how much it costs for aigcm to write the commit message for you. The style guide impacts how well the commit message is written.
|
|
110
|
+
|
|
111
|
+
#### Model
|
|
112
|
+
|
|
113
|
+
If you do not specify a model `aigcm` attempts to use `gpt-4o-mini` from OpenAI. If you want to use a different model or different provider the best way to do that is to create a shell alias like `alias aigcm='\aigcm --model o3-mini'` or `aigcm='\aigcm --model deepseek-r1 --provider ollama`
|
|
114
|
+
|
|
115
|
+
#### Style Guide
|
|
116
|
+
|
|
117
|
+
If you do not have a style guide named `COMMITS.md` in the root directory of your repo's working directory AND you do not specify a path to a style guid file using the `--style` option THEN `aigcm` will use its own default style guide. To print to STDOUT the default style guide use the `--default` option.
|
|
118
|
+
|
|
119
|
+
### Private Repos
|
|
120
|
+
|
|
121
|
+
When you specify a model or provider which is not associated with localhost processing, this gem issue an ERROR message when it is operating in a private repository. There are lots of security officiers and bosses who just do not want even a `git diff` to be shared outside of their control regardless of whether the provider "crosses their heart and hopes to die" that they do not use the data you send them.
|
|
122
|
+
|
|
123
|
+
You can by-pass this check by using the option `--force-external` or my simply using a model/provider combination that you process locally on your computer.
|
|
124
|
+
|
|
125
|
+
#### Private Repo Check Limitation
|
|
126
|
+
|
|
127
|
+
This gem uses the `gh` command to determine if the repo is private. This means 1) your repo needs to be hosted on Github; and 2) you need to have the `gh` command installed on your machine AND logged into Github. If any one of these conditions is not true, then the gem may terminate with an exception.
|
|
85
128
|
|
|
86
129
|
### Style Guide Example
|
|
87
130
|
|
|
@@ -99,19 +142,48 @@ This would be a simple style guide:
|
|
|
99
142
|
- Have fun. Be creative. Add ASCII art if you feel like it.
|
|
100
143
|
```
|
|
101
144
|
|
|
145
|
+
## API Key Configuration
|
|
146
|
+
|
|
147
|
+
Bring your own API keys to the LLM providers. This gem uses the generic `ai_client` gem to access LLM APIs. If you are using a model processed on your localhost, you most likely will not need an API key. If however, you are using an external provider then you need to acquire an API key from that provider.
|
|
148
|
+
|
|
149
|
+
The API key should be set in a system environment variable (envar) that has the pattern <provider>_API_KEY.
|
|
150
|
+
|
|
151
|
+
The following table shows a small sample of the providers supported, the envar required to be set and a link to the place to acquire an API key for the provider.
|
|
152
|
+
|
|
153
|
+
| Provider Link | envar Name |
|
|
154
|
+
| --- | --- |
|
|
155
|
+
| [Anthropic](https://www.anthropic.com/) | ANTHROPIC_API_KEY |
|
|
156
|
+
| [OpenAI](https://platform.openai.com/signup) | OPENAI_API_KEY |
|
|
157
|
+
| [OpenRouter](https://openrouter.ai/) | OPENROUTER_API_KEY |
|
|
158
|
+
| etc ... | ?_API_KEY |
|
|
159
|
+
|
|
160
|
+
Note that OpenRouter supports lots of models from many providers.
|
|
161
|
+
|
|
102
162
|
## Last Thoughts
|
|
103
163
|
|
|
164
|
+
### Support Custom Workflows
|
|
165
|
+
|
|
104
166
|
This gem saves its commit message in the file `.aigcm_msg` at the root directory of the repository. Its there even if you do a `--dry` run. This could be handy if you want to incorporate `aigcm` into some larger workflow.
|
|
105
167
|
|
|
106
168
|
Remember that the style guide can be extended using one or more `--context` strings. For example you could create a shell alias like this:
|
|
107
169
|
|
|
108
|
-
```
|
|
170
|
+
```shell
|
|
109
171
|
alias gc='aigcm -c "JIRA $JIRA_TICKET"'
|
|
110
172
|
```
|
|
111
173
|
|
|
174
|
+
### Non-deterministic Nature of LLMs
|
|
175
|
+
|
|
176
|
+
Given the same input an LLM may not (most likely will not) give you the same output as it did before. This is why we like them. This is also why we hate them.
|
|
177
|
+
|
|
178
|
+
When you do a dry run against a set of staged changes using the `--dry` option `aigcm` will print to STDOUT a commit message. It will also save that same commit message in the file `.aigcm_msg` in the root of your working directory. The commit will not be made because its a "dry run."
|
|
179
|
+
|
|
180
|
+
If you wait longer than 1 minute to run `aigcm` without the `--dry` option it will generate a new commit message which likely will be different than the one you read during the dry run. However, if you run again without the dry run option in less than a minute `aigcm` will use its previous commit message on the assumption that you liked it.
|
|
181
|
+
|
|
182
|
+
Don't forget that if you make a commit and then decide that you need to change the commit message there is always the `--amend` option available.
|
|
183
|
+
|
|
112
184
|
## Development
|
|
113
185
|
|
|
114
|
-
After checking out the repo, run `
|
|
186
|
+
After checking out the repo, run `rake test` to run the tests. Make sure that all of the tests are passing.
|
|
115
187
|
|
|
116
188
|
To install this gem onto your local machine, run `bundle exec rake install`.
|
|
117
189
|
|
data/bin/aigcm
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
|
|
2
1
|
require "net/http"
|
|
3
2
|
require "json"
|
|
4
3
|
require "open3"
|
|
5
|
-
require "
|
|
4
|
+
require "ruby_llm"
|
|
6
5
|
|
|
7
6
|
module Aigcm
|
|
8
7
|
class CommitMessageGenerator
|
|
@@ -10,17 +9,23 @@ module Aigcm
|
|
|
10
9
|
|
|
11
10
|
MAX_DIFF_SIZE = 4000 # Characters
|
|
12
11
|
|
|
13
|
-
def initialize(model:, provider:, max_tokens:, force_external:)
|
|
12
|
+
def initialize(model:, provider:, max_tokens:, force_external: false, amend: false)
|
|
13
|
+
@model = model
|
|
14
|
+
@provider = provider
|
|
15
|
+
@max_tokens = max_tokens
|
|
14
16
|
@force_external = force_external
|
|
15
|
-
|
|
17
|
+
@amend = amend
|
|
18
|
+
infer_provider_from_model
|
|
16
19
|
check_provider_availability
|
|
17
20
|
|
|
18
|
-
|
|
21
|
+
configure_ruby_llm
|
|
22
|
+
@chat = RubyLLM.chat(model: @model)
|
|
19
23
|
rescue StandardError => e
|
|
20
24
|
raise Error, "Failed to initialize AI client: #{e.message}"
|
|
21
25
|
end
|
|
22
26
|
|
|
23
|
-
def generate(
|
|
27
|
+
def generate(style_guide, context = [])
|
|
28
|
+
diff = GitDiff.new(dir: Dir.pwd, amend: @amend).generate_diff
|
|
24
29
|
return "No changes to commit" if diff.strip.empty?
|
|
25
30
|
|
|
26
31
|
check_repository_privacy unless @force_external
|
|
@@ -34,8 +39,8 @@ module Aigcm
|
|
|
34
39
|
prompt = build_prompt(diff, style_guide, processed_context)
|
|
35
40
|
|
|
36
41
|
begin
|
|
37
|
-
response = @
|
|
38
|
-
response.
|
|
42
|
+
response = @chat.ask(prompt)
|
|
43
|
+
response.content.strip
|
|
39
44
|
rescue StandardError => e
|
|
40
45
|
"Error generating commit message: #{e.message}"
|
|
41
46
|
end
|
|
@@ -43,11 +48,40 @@ module Aigcm
|
|
|
43
48
|
|
|
44
49
|
private
|
|
45
50
|
|
|
46
|
-
def
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
+
def infer_provider_from_model
|
|
52
|
+
return if @provider
|
|
53
|
+
|
|
54
|
+
model_lower = @model.to_s.downcase
|
|
55
|
+
@provider = if model_lower.include?('gpt') || model_lower.include?('o1') || model_lower.include?('o3')
|
|
56
|
+
:openai
|
|
57
|
+
elsif model_lower.include?('claude')
|
|
58
|
+
:anthropic
|
|
59
|
+
elsif model_lower.include?('gemini')
|
|
60
|
+
:google
|
|
61
|
+
elsif model_lower.include?('mistral') || model_lower.include?('mixtral')
|
|
62
|
+
:mistral
|
|
63
|
+
elsif model_lower.include?('llama') || model_lower.include?('qwen') || model_lower.include?('deepseek')
|
|
64
|
+
:ollama
|
|
65
|
+
else
|
|
66
|
+
:openai
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def configure_ruby_llm
|
|
71
|
+
RubyLLM.configure do |config|
|
|
72
|
+
case @provider
|
|
73
|
+
when :ollama
|
|
74
|
+
config.ollama_api_base = 'http://localhost:11434/v1'
|
|
75
|
+
when :openai
|
|
76
|
+
config.openai_api_key = ENV.fetch('OPENAI_API_KEY', nil)
|
|
77
|
+
when :anthropic
|
|
78
|
+
config.anthropic_api_key = ENV.fetch('ANTHROPIC_API_KEY', nil)
|
|
79
|
+
when :google
|
|
80
|
+
config.gemini_api_key = ENV.fetch('GEMINI_API_KEY', nil)
|
|
81
|
+
when :mistral
|
|
82
|
+
config.mistral_api_key = ENV.fetch('MISTRAL_API_KEY', nil)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
51
85
|
end
|
|
52
86
|
|
|
53
87
|
def check_provider_availability
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
|
|
3
|
+
module Aigcm
|
|
4
|
+
class Options
|
|
5
|
+
def self.parse
|
|
6
|
+
options = {
|
|
7
|
+
amend: false,
|
|
8
|
+
context: [],
|
|
9
|
+
dry: false,
|
|
10
|
+
model: 'gpt-4o-mini',
|
|
11
|
+
provider: nil,
|
|
12
|
+
force_external: false,
|
|
13
|
+
style: nil
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
OptionParser.new do |opts|
|
|
17
|
+
opts.banner = "Usage: aigcm [options] [ref]"
|
|
18
|
+
|
|
19
|
+
opts.on("-a", "--amend", "Amend the last commit") { options[:amend] = true }
|
|
20
|
+
|
|
21
|
+
opts.on("-cCONTEXT", "--context=CONTEXT", "Extra context beyond the diff") do |context|
|
|
22
|
+
options[:context] << context
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
opts.on("-d", "--dry", "Dry run the command") { options[:dry] = true }
|
|
26
|
+
|
|
27
|
+
opts.on("-mMODEL", "--model=MODEL", "The model to use") { |model| options[:model] = model }
|
|
28
|
+
|
|
29
|
+
opts.on("--provider=PROVIDER", "Specify the provider (ollama, openai, anthropic, etc)") do |provider|
|
|
30
|
+
provider = provider.to_sym
|
|
31
|
+
unless [:ollama, :openai, :anthropic, :google, :mistral].include?(provider)
|
|
32
|
+
puts "Invalid provider specified. Valid providers are: ollama, openai, anthropic, google, mistral"
|
|
33
|
+
exit 1
|
|
34
|
+
end
|
|
35
|
+
options[:provider] = provider
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
opts.on("--force-external", "Force using external AI provider even for private repos") {
|
|
39
|
+
options[:force_external] = true
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
opts.on("-sSTYLE", "--style=STYLE", "Path to the style guide file") { |style| options[:style] = style }
|
|
43
|
+
|
|
44
|
+
opts.on("--default", "Print the default style guide and exit") do
|
|
45
|
+
puts "\nDefault Style Guide:"
|
|
46
|
+
puts "-------------------"
|
|
47
|
+
puts StyleGuide::DEFAULT_GUIDE
|
|
48
|
+
exit
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
opts.on("--version", "Show version") { puts Aigcm::VERSION; exit }
|
|
52
|
+
|
|
53
|
+
end.parse!
|
|
54
|
+
|
|
55
|
+
options
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
data/lib/aigcm/style_guide.rb
CHANGED
|
@@ -42,9 +42,9 @@ __END__
|
|
|
42
42
|
• Use Imperative Mood: Phrase commands as direct actions (e.g., "Add feature" instead of "Added feature").
|
|
43
43
|
|
|
44
44
|
2. Provide a Detailed Body:
|
|
45
|
-
•
|
|
45
|
+
• Separate the body from the subject line with a blank line.
|
|
46
46
|
• Explain the Reason: Clearly articulate the rationale for the change rather than just summarizing the modification.
|
|
47
47
|
• Wrap Body Text at <%= Aigcm::StyleGuide::LINE_MAX %> Characters: Ensure that the body text wraps at <%= Aigcm::StyleGuide::LINE_MAX %> characters per line.
|
|
48
48
|
|
|
49
49
|
3. Reference Issues/Tickets:
|
|
50
|
-
• Include relevant issue numbers, ticket IDs and/or references when they are provided.
|
|
50
|
+
• Include relevant issue numbers, ticket IDs and/or references when they are provided. Do not invent your own reference. Use what has been provided.
|
data/lib/aigcm/version.rb
CHANGED
data/lib/aigcm.rb
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
# lib/aigcm.rb
|
|
2
|
-
|
|
3
1
|
require 'debug_me'
|
|
4
2
|
include DebugMe
|
|
5
3
|
|
|
6
4
|
require 'optparse'
|
|
7
|
-
require '
|
|
5
|
+
require 'ruby_llm'
|
|
8
6
|
require 'time'
|
|
9
7
|
|
|
10
8
|
require_relative 'aigcm/version'
|
|
11
9
|
require_relative 'aigcm/git_diff'
|
|
12
10
|
require_relative 'aigcm/commit_message_generator'
|
|
13
11
|
require_relative 'aigcm/style_guide'
|
|
12
|
+
require_relative 'aigcm/options'
|
|
14
13
|
|
|
15
14
|
module Aigcm
|
|
16
15
|
COMMIT_MESSAGE_FILE = '.aigcm_msg'
|
|
@@ -18,129 +17,102 @@ module Aigcm
|
|
|
18
17
|
|
|
19
18
|
class Error < StandardError; end
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
options = parse_options
|
|
24
|
-
|
|
25
|
-
if options[:amend]
|
|
26
|
-
system('git commit --amend')
|
|
27
|
-
return
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
commit_message = check_recent_commit(dir)
|
|
20
|
+
class << self
|
|
21
|
+
attr_reader :parsed_options
|
|
31
22
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
perform_commit(dir, commit_message, options)
|
|
36
|
-
|
|
37
|
-
rescue OptionParser::InvalidOption => e
|
|
38
|
-
STDERR.puts "Error: '#{e.message}'"
|
|
39
|
-
exit 1
|
|
40
|
-
rescue GitDiff::Error => e
|
|
41
|
-
puts "Git error: #{e.message}"
|
|
42
|
-
exit 1
|
|
43
|
-
rescue StandardError => e
|
|
44
|
-
puts "Error: #{e.message}"
|
|
45
|
-
exit 1
|
|
46
|
-
end
|
|
23
|
+
def run(test_mode: false)
|
|
24
|
+
@parsed_options = Options.parse
|
|
47
25
|
|
|
48
|
-
|
|
49
|
-
options = {
|
|
50
|
-
amend: false,
|
|
51
|
-
context: [],
|
|
52
|
-
dry: false,
|
|
53
|
-
model: 'gpt-4o-mini',
|
|
54
|
-
provider: nil,
|
|
55
|
-
force_external: false,
|
|
56
|
-
style: nil
|
|
57
|
-
}
|
|
26
|
+
dir = Dir.pwd
|
|
58
27
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
opts.on("-a", "--amend", "Amend the last commit") { options[:amend] = true }
|
|
63
|
-
|
|
64
|
-
opts.on("-cCONTEXT", "--context=CONTEXT", "Extra context beyond the diff") do |context|
|
|
65
|
-
options[:context] << context
|
|
28
|
+
if amend?
|
|
29
|
+
system('git commit --amend')
|
|
30
|
+
return
|
|
66
31
|
end
|
|
67
32
|
|
|
68
|
-
|
|
33
|
+
commit_message = check_recent_commit(dir, dry?)
|
|
69
34
|
|
|
70
|
-
|
|
35
|
+
# Generate a new commit message if not reusing an existing one
|
|
36
|
+
commit_message ||= generate_commit_message(dir)
|
|
71
37
|
|
|
72
|
-
|
|
73
|
-
provider = provider.to_sym
|
|
74
|
-
unless [:ollama, :openai, :anthropic, :google, :mistral].include?(provider)
|
|
75
|
-
puts "Invalid provider specified. Valid providers are: ollama, openai, anthropic, google, mistral"
|
|
76
|
-
exit 1
|
|
77
|
-
end
|
|
78
|
-
options[:provider] = provider
|
|
79
|
-
end
|
|
38
|
+
perform_commit(dir, commit_message)
|
|
80
39
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
40
|
+
rescue OptionParser::InvalidOption => e
|
|
41
|
+
STDERR.puts "Error: '#{e.message}'"
|
|
42
|
+
exit 1
|
|
43
|
+
rescue GitDiff::Error => e
|
|
44
|
+
puts "Git error: #{e.message}"
|
|
45
|
+
exit 1
|
|
46
|
+
rescue StandardError => e
|
|
47
|
+
puts "Error: #{e.message}"
|
|
48
|
+
exit 1
|
|
49
|
+
end
|
|
84
50
|
|
|
85
|
-
|
|
51
|
+
def dry?
|
|
52
|
+
parsed_options[:dry]
|
|
53
|
+
end
|
|
86
54
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
puts StyleGuide::DEFAULT_GUIDE
|
|
91
|
-
exit
|
|
92
|
-
end
|
|
55
|
+
def amend?
|
|
56
|
+
parsed_options[:amend]
|
|
57
|
+
end
|
|
93
58
|
|
|
94
|
-
|
|
59
|
+
def model
|
|
60
|
+
parsed_options[:model]
|
|
61
|
+
end
|
|
95
62
|
|
|
96
|
-
|
|
63
|
+
def provider
|
|
64
|
+
parsed_options[:provider]
|
|
65
|
+
end
|
|
97
66
|
|
|
98
|
-
|
|
99
|
-
end
|
|
67
|
+
private
|
|
100
68
|
|
|
101
|
-
|
|
102
|
-
|
|
69
|
+
def check_recent_commit(dir, dry_run)
|
|
70
|
+
commit_file_path = File.join(dir, COMMIT_MESSAGE_FILE)
|
|
103
71
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
72
|
+
if File.exist?(commit_file_path)
|
|
73
|
+
file_mod_time = File.mtime(commit_file_path)
|
|
74
|
+
current_time = Time.now
|
|
75
|
+
if (current_time - file_mod_time).to_i < RECENT_THRESHOLD
|
|
76
|
+
return nil if dry_run # Skip time check in dry run mode
|
|
77
|
+
return File.read(commit_file_path)
|
|
78
|
+
end
|
|
109
79
|
end
|
|
110
|
-
end
|
|
111
80
|
|
|
112
|
-
|
|
113
|
-
|
|
81
|
+
nil
|
|
82
|
+
end
|
|
114
83
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
84
|
+
def generate_commit_message(dir)
|
|
85
|
+
commit_hash = ARGV.shift # This may be nil
|
|
86
|
+
diff_generator = GitDiff.new(dir: dir, commit_hash: commit_hash, amend: amend?)
|
|
87
|
+
diff = diff_generator.generate_diff
|
|
88
|
+
|
|
89
|
+
style_guide = StyleGuide.load(dir, parsed_options[:style])
|
|
90
|
+
generator = CommitMessageGenerator.new(
|
|
91
|
+
model: model,
|
|
92
|
+
provider: provider,
|
|
93
|
+
max_tokens: 1000,
|
|
94
|
+
force_external: parsed_options[:force_external],
|
|
95
|
+
amend: amend?
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
commit_message = generator.generate(style_guide, parsed_options[:context])
|
|
99
|
+
File.write(File.join(dir, COMMIT_MESSAGE_FILE), commit_message)
|
|
100
|
+
commit_message
|
|
101
|
+
end
|
|
131
102
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
103
|
+
def perform_commit(dir, commit_message)
|
|
104
|
+
commit_file_path = File.join(dir, COMMIT_MESSAGE_FILE)
|
|
105
|
+
|
|
106
|
+
if dry?
|
|
107
|
+
puts "\nDry run - would generate commit message:"
|
|
108
|
+
puts "-"*StyleGuide::LINE_MAX
|
|
109
|
+
puts commit_message
|
|
110
|
+
puts "-"*StyleGuide::LINE_MAX
|
|
111
|
+
puts
|
|
112
|
+
else
|
|
113
|
+
File.write(commit_file_path, commit_message)
|
|
114
|
+
system("git commit --edit -F #{commit_file_path}")
|
|
115
|
+
end
|
|
144
116
|
end
|
|
145
117
|
end
|
|
146
118
|
end
|
metadata
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: aigcm
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dewayne VanHoozer
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
|
-
name:
|
|
13
|
+
name: ruby_llm
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
15
15
|
requirements:
|
|
16
|
-
- - "
|
|
16
|
+
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
|
-
version: 0
|
|
18
|
+
version: '0'
|
|
19
19
|
type: :runtime
|
|
20
20
|
prerelease: false
|
|
21
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
22
22
|
requirements:
|
|
23
|
-
- - "
|
|
23
|
+
- - ">="
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
|
-
version: 0
|
|
25
|
+
version: '0'
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: minitest
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -79,16 +79,27 @@ dependencies:
|
|
|
79
79
|
- - "~>"
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
81
|
version: '1.21'
|
|
82
|
+
- !ruby/object:Gem::Dependency
|
|
83
|
+
name: debug_me
|
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
|
85
|
+
requirements:
|
|
86
|
+
- - ">="
|
|
87
|
+
- !ruby/object:Gem::Version
|
|
88
|
+
version: '0'
|
|
89
|
+
type: :development
|
|
90
|
+
prerelease: false
|
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
92
|
+
requirements:
|
|
93
|
+
- - ">="
|
|
94
|
+
- !ruby/object:Gem::Version
|
|
95
|
+
version: '0'
|
|
82
96
|
description: |
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
commits and handling staged changes. The gem follows conventional
|
|
90
|
-
commit message formats and allows customization of commit message
|
|
91
|
-
styles through configuration.
|
|
97
|
+
An advanced AI-powered git commit message generator. It leverages
|
|
98
|
+
multiple AI providers including OpenAI, Anthropic, Google, and
|
|
99
|
+
local models via Ollama to create meaningful and contextual commit
|
|
100
|
+
messages. This gem streamlines the commit process, ensuring
|
|
101
|
+
consistent and informative version control practices across
|
|
102
|
+
projects.
|
|
92
103
|
email:
|
|
93
104
|
- dvanhoozer@gmail.com
|
|
94
105
|
executables:
|
|
@@ -98,6 +109,7 @@ extra_rdoc_files: []
|
|
|
98
109
|
files:
|
|
99
110
|
- ".envrc"
|
|
100
111
|
- CHANGELOG.md
|
|
112
|
+
- COMMITS.md
|
|
101
113
|
- LICENSE.txt
|
|
102
114
|
- README.md
|
|
103
115
|
- Rakefile
|
|
@@ -105,6 +117,7 @@ files:
|
|
|
105
117
|
- lib/aigcm.rb
|
|
106
118
|
- lib/aigcm/commit_message_generator.rb
|
|
107
119
|
- lib/aigcm/git_diff.rb
|
|
120
|
+
- lib/aigcm/options.rb
|
|
108
121
|
- lib/aigcm/style_guide.rb
|
|
109
122
|
- lib/aigcm/version.rb
|
|
110
123
|
- sig/aicommit.rbs
|
|
@@ -130,7 +143,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
130
143
|
- !ruby/object:Gem::Version
|
|
131
144
|
version: '0'
|
|
132
145
|
requirements: []
|
|
133
|
-
rubygems_version:
|
|
146
|
+
rubygems_version: 4.0.0.dev
|
|
134
147
|
specification_version: 4
|
|
135
148
|
summary: AI-powered git commit message generator
|
|
136
149
|
test_files: []
|