lazycommitt 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +270 -0
- package/dist/cli.mjs +72 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2025 Kartik Labhshetwar
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<div>
|
|
3
|
+
<h1 align="center">lazycommit</h1>
|
|
4
|
+
</div>
|
|
5
|
+
<p>A CLI that writes your git commit messages for you with AI using Groq. Never write a commit message again.</p>
|
|
6
|
+
<a href="https://www.npmjs.com/package/lazycommitz"><img src="https://img.shields.io/npm/v/lazycommitz" alt="Current version"></a>
|
|
7
|
+
<a href="https://github.com/KartikLabhshetwar/lazycommit"><img src="https://img.shields.io/github/stars/KartikLabhshetwar/lazycommit" alt="GitHub stars"></a>
|
|
8
|
+
<a href="https://github.com/KartikLabhshetwar/lazycommit/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/lazycommitz" alt="License"></a>
|
|
9
|
+
</div>
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Setup
|
|
14
|
+
|
|
15
|
+
> The minimum supported version of Node.js is v18. Check your Node.js version with `node --version`.
|
|
16
|
+
|
|
17
|
+
1. Install _lazycommit_:
|
|
18
|
+
|
|
19
|
+
```sh
|
|
20
|
+
npm install -g lazycommitz
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
2. Retrieve your API key from [Groq Console](https://console.groq.com/keys)
|
|
24
|
+
|
|
25
|
+
> Note: If you haven't already, you'll have to create an account and get your API key.
|
|
26
|
+
|
|
27
|
+
3. Set the key so lazycommit can use it:
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
lazycommit config set GROQ_API_KEY=<your token>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
This will create a `.lazycommit` file in your home directory.
|
|
34
|
+
|
|
35
|
+
### Upgrading
|
|
36
|
+
|
|
37
|
+
Check the installed version with:
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
lazycommit --version
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
If it's not the [latest version](https://github.com/KartikLabhshetwar/lazycommit/releases/latest), run:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npm update -g lazycommitz
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
### CLI mode
|
|
52
|
+
|
|
53
|
+
You can call `lazycommit` directly to generate a commit message for your staged changes:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
git add <files...>
|
|
57
|
+
lazycommit
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
`lazycommit` passes down unknown flags to `git commit`, so you can pass in [`commit` flags](https://git-scm.com/docs/git-commit).
|
|
61
|
+
|
|
62
|
+
For example, you can stage all changes in tracked files as you commit:
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
lazycommit --all # or -a
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
> 👉 **Tip:** Use the `lzc` alias if `lazycommit` is too long for you.
|
|
69
|
+
|
|
70
|
+
#### Generate multiple recommendations
|
|
71
|
+
|
|
72
|
+
Sometimes the recommended commit message isn't the best so you want it to generate a few to pick from. You can generate multiple commit messages at once by passing in the `--generate <i>` flag, where 'i' is the number of generated messages:
|
|
73
|
+
|
|
74
|
+
```sh
|
|
75
|
+
lazycommit --generate <i> # or -g <i>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
> Warning: this uses more tokens, meaning it costs more.
|
|
79
|
+
|
|
80
|
+
#### Generating Conventional Commits
|
|
81
|
+
|
|
82
|
+
If you'd like to generate [Conventional Commits](https://conventionalcommits.org/), you can use the `--type` flag followed by `conventional`. This will prompt `lazycommit` to format the commit message according to the Conventional Commits specification:
|
|
83
|
+
|
|
84
|
+
```sh
|
|
85
|
+
lazycommit --type conventional # or -t conventional
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
This feature can be useful if your project follows the Conventional Commits standard or if you're using tools that rely on this commit format.
|
|
89
|
+
|
|
90
|
+
#### Exclude files from analysis
|
|
91
|
+
|
|
92
|
+
You can exclude specific files from AI analysis using the `--exclude` flag:
|
|
93
|
+
|
|
94
|
+
```sh
|
|
95
|
+
lazycommit --exclude package-lock.json --exclude dist/
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### Git hook
|
|
99
|
+
|
|
100
|
+
You can also integrate _lazycommit_ with Git via the [`prepare-commit-msg`](https://git-scm.com/docs/githooks#_prepare_commit_msg) hook. This lets you use Git like you normally would, and edit the commit message before committing.
|
|
101
|
+
|
|
102
|
+
#### Install
|
|
103
|
+
|
|
104
|
+
In the Git repository you want to install the hook in:
|
|
105
|
+
|
|
106
|
+
```sh
|
|
107
|
+
lazycommit hook install
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
#### Uninstall
|
|
111
|
+
|
|
112
|
+
In the Git repository you want to uninstall the hook from:
|
|
113
|
+
|
|
114
|
+
```sh
|
|
115
|
+
lazycommit hook uninstall
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
#### Usage
|
|
119
|
+
|
|
120
|
+
1. Stage your files and commit:
|
|
121
|
+
|
|
122
|
+
```sh
|
|
123
|
+
git add <files...>
|
|
124
|
+
git commit # Only generates a message when it's not passed in
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
> If you ever want to write your own message instead of generating one, you can simply pass one in: `git commit -m "My message"`
|
|
128
|
+
|
|
129
|
+
2. Lazycommit will generate the commit message for you and pass it back to Git. Git will open it with the [configured editor](https://docs.github.com/en/get-started/getting-started-with-git/associating-text-editors-with-git) for you to review/edit it.
|
|
130
|
+
|
|
131
|
+
3. Save and close the editor to commit!
|
|
132
|
+
|
|
133
|
+
## Configuration
|
|
134
|
+
|
|
135
|
+
### Reading a configuration value
|
|
136
|
+
|
|
137
|
+
To retrieve a configuration option, use the command:
|
|
138
|
+
|
|
139
|
+
```sh
|
|
140
|
+
lazycommit config get <key>
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
For example, to retrieve the API key, you can use:
|
|
144
|
+
|
|
145
|
+
```sh
|
|
146
|
+
lazycommit config get GROQ_API_KEY
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
You can also retrieve multiple configuration options at once by separating them with spaces:
|
|
150
|
+
|
|
151
|
+
```sh
|
|
152
|
+
lazycommit config get GROQ_API_KEY generate
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Setting a configuration value
|
|
156
|
+
|
|
157
|
+
To set a configuration option, use the command:
|
|
158
|
+
|
|
159
|
+
```sh
|
|
160
|
+
lazycommit config set <key>=<value>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
For example, to set the API key, you can use:
|
|
164
|
+
|
|
165
|
+
```sh
|
|
166
|
+
lazycommit config set GROQ_API_KEY=<your-api-key>
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
You can also set multiple configuration options at once by separating them with spaces, like
|
|
170
|
+
|
|
171
|
+
```sh
|
|
172
|
+
lazycommit config set GROQ_API_KEY=<your-api-key> generate=3 locale=en
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### Options
|
|
176
|
+
|
|
177
|
+
#### GROQ_API_KEY
|
|
178
|
+
|
|
179
|
+
Required
|
|
180
|
+
|
|
181
|
+
The Groq API key. You can retrieve it from [Groq Console](https://console.groq.com/keys).
|
|
182
|
+
|
|
183
|
+
#### locale
|
|
184
|
+
|
|
185
|
+
Default: `en`
|
|
186
|
+
|
|
187
|
+
The locale to use for the generated commit messages. Consult the list of codes in: https://wikipedia.org/wiki/List_of_ISO_639-1_codes.
|
|
188
|
+
|
|
189
|
+
#### generate
|
|
190
|
+
|
|
191
|
+
Default: `1`
|
|
192
|
+
|
|
193
|
+
The number of commit messages to generate to pick from.
|
|
194
|
+
|
|
195
|
+
Note, this will use more tokens as it generates more results.
|
|
196
|
+
|
|
197
|
+
#### proxy
|
|
198
|
+
|
|
199
|
+
Set a HTTP/HTTPS proxy to use for requests.
|
|
200
|
+
|
|
201
|
+
To clear the proxy option, you can use the command (note the empty value after the equals sign):
|
|
202
|
+
|
|
203
|
+
```sh
|
|
204
|
+
lazycommit config set proxy=
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
#### model
|
|
208
|
+
|
|
209
|
+
Default: `Openai/gpt-oss-120b`
|
|
210
|
+
|
|
211
|
+
#### timeout
|
|
212
|
+
|
|
213
|
+
The timeout for network requests to the Groq API in milliseconds.
|
|
214
|
+
|
|
215
|
+
Default: `10000` (10 seconds)
|
|
216
|
+
|
|
217
|
+
```sh
|
|
218
|
+
lazycommit config set timeout=20000 # 20s
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
#### max-length
|
|
222
|
+
|
|
223
|
+
The maximum character length of the generated commit message.
|
|
224
|
+
|
|
225
|
+
Default: `50`
|
|
226
|
+
|
|
227
|
+
```sh
|
|
228
|
+
lazycommit config set max-length=100
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
#### type
|
|
232
|
+
|
|
233
|
+
Default: `""` (Empty string)
|
|
234
|
+
|
|
235
|
+
The type of commit message to generate. Set this to "conventional" to generate commit messages that follow the Conventional Commits specification:
|
|
236
|
+
|
|
237
|
+
```sh
|
|
238
|
+
lazycommit config set type=conventional
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
You can clear this option by setting it to an empty string:
|
|
242
|
+
|
|
243
|
+
```sh
|
|
244
|
+
lazycommit config set type=
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
## How it works
|
|
248
|
+
|
|
249
|
+
This CLI tool runs `git diff` to grab all your latest code changes, sends them to Groq's AI models, then returns the AI generated commit message.
|
|
250
|
+
|
|
251
|
+
The tool uses Groq's fast inference API to provide quick and accurate commit message suggestions based on your code changes.
|
|
252
|
+
|
|
253
|
+
## Why Groq?
|
|
254
|
+
|
|
255
|
+
- **Fast**: Groq provides ultra-fast inference speeds
|
|
256
|
+
- **Cost-effective**: More affordable than traditional AI APIs
|
|
257
|
+
- **Open source models**: Uses leading open-source language models
|
|
258
|
+
- **Reliable**: High uptime and consistent performance
|
|
259
|
+
|
|
260
|
+
## Maintainers
|
|
261
|
+
|
|
262
|
+
- **Kartik Labhshetwar**: [@KartikLabhshetwar](https://github.com/KartikLabhshetwar)
|
|
263
|
+
|
|
264
|
+
## Contributing
|
|
265
|
+
|
|
266
|
+
If you want to help fix a bug or implement a feature in [Issues](https://github.com/KartikLabhshetwar/lazycommit/issues), checkout the [Contribution Guide](CONTRIBUTING.md) to learn how to setup and test the project.
|
|
267
|
+
|
|
268
|
+
## License
|
|
269
|
+
|
|
270
|
+
This project is licensed under the Apache-2.0 License - see the [LICENSE](LICENSE) file for details.
|
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var se=Object.defineProperty;var n=(e,t)=>se(e,"name",{value:t,configurable:!0});import{command as S,cli as oe}from"cleye";import{readFileSync as ae}from"fs";import{fileURLToPath as F,pathToFileURL as ne}from"url";import P,{dirname as ie,join as re}from"path";import{execa as $}from"execa";import{dim as C,bgCyan as z,black as G,green as b,red as v}from"kolorist";import{intro as Y,spinner as _,confirm as ce,isCancel as N,outro as w,select as le}from"@clack/prompts";import p from"fs/promises";import me from"os";import j from"ini";import U from"groq-sdk";var fe="1.0.0",ge={version:fe};const R=class R extends Error{};n(R,"KnownError");let m=R;const I=" ",k=n(e=>{e instanceof Error&&!(e instanceof m)&&(e.stack&&console.error(C(e.stack.split(`
|
|
3
|
+
`).slice(1).join(`
|
|
4
|
+
`))),console.error(`
|
|
5
|
+
${I}${C(`lazycommit v${ge.version}`)}`),console.error(`
|
|
6
|
+
${I}Please open a Bug report with the information above:`),console.error(`${I}https://github.com/KartikLabhshetwar/lazycommit/issues/new/choose`))},"handleCliError"),H=n(async()=>{const{stdout:e,failed:t}=await $("git",["rev-parse","--show-toplevel"],{reject:!1});if(t)throw new m("The current directory must be a Git repository!");return e},"assertGitRepo"),O=n(e=>`:(exclude)${e}`,"excludeFromDiff"),D=["package-lock.json","pnpm-lock.yaml","*.lock"].map(O),Q=n(async e=>{const t=["diff","--cached","--diff-algorithm=minimal"],{stdout:s}=await $("git",[...t,"--name-only",...D,...e?e.map(O):[]]);if(!s)return;const{stdout:o}=await $("git",[...t,...D,...e?e.map(O):[]]);return{files:s.split(`
|
|
7
|
+
`),diff:o}},"getStagedDiff"),pe=n(e=>`Detected ${e.length.toLocaleString()} staged file${e.length>1?"s":""}`,"getDetectedMessage"),K=n(e=>p.lstat(e).then(()=>!0,()=>!1),"fileExists"),de=["","conventional"],{hasOwnProperty:he}=Object.prototype,J=n((e,t)=>he.call(e,t),"hasOwn"),d=n((e,t,s)=>{if(!t)throw new m(`Invalid config property ${e}: ${s}`)},"parseAssert"),x={GROQ_API_KEY(e){if(!e)throw new m("Please set your Groq API key via `lazycommit config set GROQ_API_KEY=<your token>`");return d("GROQ_API_KEY",e.startsWith("gsk_"),'Must start with "gsk_"'),e},locale(e){return e?(d("locale",e,"Cannot be empty"),d("locale",/^[a-z-]+$/i.test(e),"Must be a valid locale (letters and dashes/underscores). You can consult the list of codes in: https://wikipedia.org/wiki/List_of_ISO_639-1_codes"),e):"en"},generate(e){if(!e)return 1;d("generate",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return d("generate",t>0,"Must be greater than 0"),d("generate",t<=5,"Must be less or equal to 5"),t},type(e){return e?(d("type",de.includes(e),"Invalid commit type"),e):""},proxy(e){if(!(!e||e.length===0))return d("proxy",/^https?:\/\//.test(e),"Must be a valid URL"),e},model(e){return!e||e.length===0?"openai/gpt-oss-120b":e},timeout(e){if(!e)return 1e4;d("timeout",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return d("timeout",t>=500,"Must be greater than 500ms"),t},"max-length"(e){if(!e)return 50;d("max-length",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return d("max-length",t>=20,"Must be greater than 20 characters"),t}},T=P.join(me.homedir(),".lazycommit"),L=n(async()=>{if(!await K(T))return Object.create(null);const t=await p.readFile(T,"utf8");return j.parse(t)},"readConfigFile"),E=n(async(e,t)=>{const s=await L(),o={};for(const a of Object.keys(x)){const c=x[a],l=e?.[a]??s[a];if(t)try{o[a]=c(l)}catch{}else o[a]=c(l)}return o},"getConfig"),ue=n(async e=>{const t=await L();for(const[s,o]of e){if(!J(x,s))throw new m(`Invalid config property: ${s}`);const a=x[s](o);t[s]=a}await p.writeFile(T,j.stringify(t),"utf8")},"setConfigs"),ye={"":"<commit message>",conventional:"<type>(<optional scope>): <commit message>"},W={"":"",conventional:`Choose the most appropriate type from the following categories that best describes the git diff:
|
|
8
|
+
|
|
9
|
+
${JSON.stringify({feat:"A new feature for the user",fix:"A bug fix",docs:"Documentation only changes",style:"Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)",refactor:"A code change that neither fixes a bug nor adds a feature",perf:"A code change that improves performance",test:"Adding missing tests or correcting existing tests",build:"Changes that affect the build system or external dependencies",ci:"Changes to our CI configuration files and scripts",chore:"Other changes that don't modify src or test files",revert:"Reverts a previous commit"},null,2)}
|
|
10
|
+
|
|
11
|
+
IMPORTANT: Use the exact type name from the list above.`},we=n((e,t,s)=>`You are an expert software engineer and git commit message writer. Your task is to analyze git diffs and generate clear, concise, and professional commit messages.
|
|
12
|
+
|
|
13
|
+
## Instructions:
|
|
14
|
+
1. Analyze the provided git diff carefully
|
|
15
|
+
2. Identify the primary purpose and impact of the changes
|
|
16
|
+
3. Generate a commit message that clearly describes what was changed and why
|
|
17
|
+
4. Use present tense, imperative mood (e.g., "feat: Add feature" not "Added feature")
|
|
18
|
+
5. Be specific about what changed, not just how it changed
|
|
19
|
+
6. Focus on the business value or technical improvement
|
|
20
|
+
|
|
21
|
+
## Quality Guidelines:
|
|
22
|
+
- Be concise but descriptive
|
|
23
|
+
- Use active voice
|
|
24
|
+
- Avoid vague terms like "update", "change", "fix stuff"
|
|
25
|
+
- Include context when helpful (e.g., "fix: memory leak in user authentication")
|
|
26
|
+
- For bug fixes, briefly describe what was broken
|
|
27
|
+
- For features, describe what functionality was added
|
|
28
|
+
- For refactoring, mention what was improved (performance, readability, etc.)
|
|
29
|
+
|
|
30
|
+
## Language: ${e}
|
|
31
|
+
## Maximum length: ${t} characters
|
|
32
|
+
## Output format: ${ye[s]||"<commit message>"}
|
|
33
|
+
|
|
34
|
+
${W[s]?`
|
|
35
|
+
## Commit Type Guidelines:
|
|
36
|
+
${W[s]}`:""}
|
|
37
|
+
|
|
38
|
+
## Examples of good commit messages:
|
|
39
|
+
- "feat: Add user authentication with JWT tokens"
|
|
40
|
+
- "fix: Fix memory leak in image processing pipeline"
|
|
41
|
+
- "refactor: Refactor database queries to use prepared statements"
|
|
42
|
+
- "docs: Update README with installation instructions"
|
|
43
|
+
- "style: Remove deprecated API endpoints"
|
|
44
|
+
- "perf: Optimize bundle size by removing unused dependencies"
|
|
45
|
+
|
|
46
|
+
## Examples of bad commit messages:
|
|
47
|
+
- "Update code"
|
|
48
|
+
- "Fix bug"
|
|
49
|
+
- "Changes"
|
|
50
|
+
- "WIP"
|
|
51
|
+
- "Stuff"
|
|
52
|
+
|
|
53
|
+
Remember: Your response will be used directly as the git commit message. Make it professional and informative.`,"generatePrompt"),$e=n(async(e,t,s,o,a,c,l,g,i,h,f)=>{const u=new U({apiKey:e,timeout:h});try{return i>1?{choices:(await Promise.all(Array.from({length:i},()=>u.chat.completions.create({model:t,messages:s,temperature:o,top_p:a,frequency_penalty:c,presence_penalty:l,max_tokens:g,n:1})))).flatMap(te=>te.choices)}:await u.chat.completions.create({model:t,messages:s,temperature:o,top_p:a,frequency_penalty:c,presence_penalty:l,max_tokens:g,n:1})}catch(r){if(r instanceof U.APIError){let y=`Groq API Error: ${r.status} - ${r.name}`;throw r.message&&(y+=`
|
|
54
|
+
|
|
55
|
+
${r.message}`),r.status===500&&(y+=`
|
|
56
|
+
|
|
57
|
+
Check the API status: https://console.groq.com/status`),new m(y)}throw r.code==="ENOTFOUND"?new m(`Error connecting to ${r.hostname} (${r.syscall}). Are you connected to the internet?`):r}},"createChatCompletion"),be=n(e=>e.trim().replace(/[\n\r]/g,"").replace(/(\w)\.$/,"$1"),"sanitizeMessage"),ve=n(e=>Array.from(new Set(e)),"deduplicateMessages"),q=n(async(e,t,s,o,a,c,l,g,i)=>{try{const h=await $e(e,t,[{role:"system",content:we(s,c,l)},{role:"user",content:o}],.7,1,0,0,200,a,g,i);return ve(h.choices.filter(f=>f.message?.content).map(f=>be(f.message.content)))}catch(h){const f=h;throw f.code==="ENOTFOUND"?new m(`Error connecting to ${f.hostname} (${f.syscall}). Are you connected to the internet?`):f}},"generateCommitMessage");var ke=n(async(e,t,s,o,a)=>(async()=>{Y(z(G(" lazycommit "))),await H();const c=_();s&&await $("git",["add","--update"]),c.start("Detecting staged files");const l=await Q(t);if(!l)throw c.stop("Detecting staged files"),new m("No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` flag.");c.stop(`${pe(l.files)}:
|
|
58
|
+
${l.files.map(r=>` ${r}`).join(`
|
|
59
|
+
`)}`);const{env:g}=process,i=await E({GROQ_API_KEY:g.GROQ_API_KEY,proxy:g.https_proxy||g.HTTPS_PROXY||g.http_proxy||g.HTTP_PROXY,generate:e?.toString(),type:o?.toString()}),h=_();h.start("The AI is analyzing your changes");let f;try{f=await q(i.GROQ_API_KEY,i.model,i.locale,l.diff,i.generate,i["max-length"],i.type,i.timeout,i.proxy)}finally{h.stop("Changes analyzed")}if(f.length===0)throw new m("No commit messages were generated. Try again.");let u;if(f.length===1){[u]=f;const r=await ce({message:`Use this commit message?
|
|
60
|
+
|
|
61
|
+
${u}
|
|
62
|
+
`});if(!r||N(r)){w("Commit cancelled");return}}else{const r=await le({message:`Pick a commit message to use: ${C("(Ctrl+c to exit)")}`,options:f.map(y=>({label:y,value:y}))});if(N(r)){w("Commit cancelled");return}u=r}await $("git",["commit","-m",u,...a]),w(`${b("\u2714")} Successfully committed!`)})().catch(c=>{w(`${v("\u2716")} ${c.message}`),k(c),process.exit(1)}),"lazycommit");const[M,xe]=process.argv.slice(2);var Ae=n(()=>(async()=>{if(!M)throw new m('Commit message file path is missing. This file should be called from the "prepare-commit-msg" git hook');if(xe)return;const e=await Q();if(!e)return;Y(z(G(" lazycommit ")));const{env:t}=process,s=await E({GROQ_API_KEY:t.GROQ_API_KEY,proxy:t.https_proxy||t.HTTPS_PROXY||t.http_proxy||t.HTTP_PROXY}),o=_();o.start("The AI is analyzing your changes");let a;try{a=await q(s.GROQ_API_KEY,s.model,s.locale,e.diff,s.generate,s["max-length"],s.type,s.timeout,s.proxy)}finally{o.stop("Changes analyzed")}const l=await p.readFile(M,"utf8")!=="",g=a.length>1;let i="";l&&(i=`# \u{1F916} AI generated commit${g?"s":""}
|
|
63
|
+
`),g?(l&&(i+=`# Select one of the following messages by uncommeting:
|
|
64
|
+
`),i+=`
|
|
65
|
+
${a.map(h=>`# ${h}`).join(`
|
|
66
|
+
`)}`):(l&&(i+=`# Edit the message below and commit:
|
|
67
|
+
`),i+=`
|
|
68
|
+
${a[0]}
|
|
69
|
+
`),await p.appendFile(M,i),w(`${b("\u2714")} Saved commit message!`)})().catch(e=>{w(`${v("\u2716")} ${e.message}`),k(e),process.exit(1)}),"prepareCommitMessageHook"),Pe=S({name:"config",parameters:["<mode>","<key=value...>"]},e=>{(async()=>{const{mode:t,keyValue:s}=e._;if(t==="get"){const o=await E({},!0);for(const a of s)J(o,a)&&console.log(`${a}=${o[a]}`);return}if(t==="set"){await ue(s.map(o=>o.split("=")));return}throw new m(`Invalid mode: ${t}`)})().catch(t=>{console.error(`${v("\u2716")} ${t.message}`),k(t),process.exit(1)})});const B="prepare-commit-msg",X=`.git/hooks/${B}`,A=F(new URL("cli.mjs",import.meta.url)),Ce=process.argv[1].replace(/\\/g,"/").endsWith(`/${X}`),V=process.platform==="win32",Z=`
|
|
70
|
+
#!/usr/bin/env node
|
|
71
|
+
import(${JSON.stringify(ne(A))})
|
|
72
|
+
`.trim();var _e=S({name:"hook",parameters:["<install/uninstall>"]},e=>{(async()=>{const t=await H(),{installUninstall:s}=e._,o=P.join(t,X),a=await K(o);if(s==="install"){if(a){if(await p.realpath(o).catch(()=>{})===A){console.warn("The hook is already installed");return}throw new m(`A different ${B} hook seems to be installed. Please remove it before installing lazycommit.`)}await p.mkdir(P.dirname(o),{recursive:!0}),V?await p.writeFile(o,Z):(await p.symlink(A,o,"file"),await p.chmod(o,493)),console.log(`${b("\u2714")} Hook installed`);return}if(s==="uninstall"){if(!a){console.warn("Hook is not installed");return}if(V){if(await p.readFile(o,"utf8")!==Z){console.warn("Hook is not installed");return}}else if(await p.realpath(o)!==A){console.warn("Hook is not installed");return}await p.rm(o),console.log(`${b("\u2714")} Hook uninstalled`);return}throw new m(`Invalid mode: ${s}`)})().catch(t=>{console.error(`${v("\u2716")} ${t.message}`),k(t),process.exit(1)})});const Ie=F(import.meta.url),Oe=ie(Ie),Te=JSON.parse(ae(re(Oe,"../package.json"),"utf8")),{description:Ee,version:Me}=Te,ee=process.argv.slice(2);oe({name:"lazycommit",version:Me,flags:{generate:{type:Number,description:"Number of messages to generate (Warning: generating multiple costs more) (default: 1)",alias:"g"},exclude:{type:[String],description:"Files to exclude from AI analysis",alias:"x"},all:{type:Boolean,description:"Automatically stage changes in tracked files for the commit",alias:"a",default:!1},type:{type:String,description:"Type of commit message to generate",alias:"t"}},commands:[Pe,_e],help:{description:Ee},ignoreArgv:n(e=>e==="unknown-flag"||e==="argument","ignoreArgv")},e=>{Ce?Ae():ke(e.flags.generate,e.flags.exclude,e.flags.all,e.flags.type,ee)},ee);
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lazycommitt",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Writes your git commit messages for you with AI using Groq",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"git",
|
|
8
|
+
"commit",
|
|
9
|
+
"ai",
|
|
10
|
+
"groq",
|
|
11
|
+
"github",
|
|
12
|
+
"cli"
|
|
13
|
+
],
|
|
14
|
+
"author": "Kartik Labhshetwar",
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"repository": "KartikLabhshetwar/lazycommit",
|
|
17
|
+
"type": "module",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"bin": {
|
|
22
|
+
"lazycommit": "./dist/cli.mjs",
|
|
23
|
+
"lzc": "./dist/cli.mjs"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@clack/prompts": "^0.11.0",
|
|
27
|
+
"@types/ini": "^4.1.1",
|
|
28
|
+
"@types/inquirer": "^9.0.9",
|
|
29
|
+
"@types/node": "^24.5.1",
|
|
30
|
+
"clean-pkg-json": "^1.3.0",
|
|
31
|
+
"cleye": "^1.3.4",
|
|
32
|
+
"execa": "^9.6.0",
|
|
33
|
+
"fs-fixture": "^2.8.1",
|
|
34
|
+
"groq-sdk": "^0.32.0",
|
|
35
|
+
"https-proxy-agent": "^7.0.6",
|
|
36
|
+
"ini": "^5.0.0",
|
|
37
|
+
"kolorist": "^1.8.0",
|
|
38
|
+
"manten": "^1.5.0",
|
|
39
|
+
"pkgroll": "^2.15.4",
|
|
40
|
+
"tsx": "^4.20.5",
|
|
41
|
+
"typescript": "^5.9.2"
|
|
42
|
+
}
|
|
43
|
+
}
|