@sachinthapa572/lazycommit 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 +488 -0
- package/dist/cli.mjs +168 -0
- package/package.json +49 -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,488 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<div>
|
|
3
|
+
<h1 align="center">lazycommit</h1>
|
|
4
|
+
<img width="2816" height="1536" alt="lazycommit" src="https://github.com/user-attachments/assets/ee0419ef-2461-4b45-8509-973f3bb0f55c" />
|
|
5
|
+
|
|
6
|
+
</div>
|
|
7
|
+
<p>A CLI that writes your git commit messages for you with AI providers. Never write a commit message again.</p>
|
|
8
|
+
<a href="https://www.npmjs.com/package/lazycommitz"><img src="https://img.shields.io/npm/v/lazycommitt" alt="Current version"></a>
|
|
9
|
+
<a href="https://github.com/KartikLabhshetwar/lazycommit"><img src="https://img.shields.io/github/stars/KartikLabhshetwar/lazycommit" alt="GitHub stars"></a>
|
|
10
|
+
<a href="https://github.com/KartikLabhshetwar/lazycommit/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/lazycommitt" alt="License"></a>
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
<div align="center">
|
|
16
|
+
<a href="https://peerlist.io/code_kartik/project/lazycommit" ><img width="400" height="128" alt="LazyCommit" src="https://github.com/user-attachments/assets/5d54d238-38f4-44f2-b253-3959b2487987" /></a>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
## Setup
|
|
20
|
+
|
|
21
|
+
> The minimum supported version of Node.js is v18. Check your Node.js version with `node --version`.
|
|
22
|
+
|
|
23
|
+
1. Install _lazycommit_:
|
|
24
|
+
|
|
25
|
+
```sh
|
|
26
|
+
npm install -g lazycommitt
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### Install via Homebrew (macOS)
|
|
30
|
+
|
|
31
|
+
Install via Homebrew tap:
|
|
32
|
+
|
|
33
|
+
```sh
|
|
34
|
+
brew tap KartikLabhshetwar/lazycommit https://github.com/KartikLabhshetwar/lazycommit
|
|
35
|
+
brew install lazycommit
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Upgrade:
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
brew update
|
|
42
|
+
brew upgrade lazycommit
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
2. Choose your provider:
|
|
46
|
+
- **Groq** (default): retrieve your API key from [Groq Console](https://console.groq.com/keys)
|
|
47
|
+
- **GitHub Copilot**: install and login to Copilot CLI:
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
copilot auth login
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
3. Configure lazycommit:
|
|
54
|
+
|
|
55
|
+
```sh
|
|
56
|
+
lazycommit config
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
For Groq, you can also set the key directly:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
lazycommit config set GROQ_API_KEY=<your token>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
This creates a `.lazycommit` file in your home directory.
|
|
66
|
+
|
|
67
|
+
### Upgrading
|
|
68
|
+
|
|
69
|
+
Check the installed version with:
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
lazycommit --version
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
If it's not the [latest version](https://github.com/KartikLabhshetwar/lazycommit/releases/latest), run:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
npm update -g lazycommitt
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Usage
|
|
82
|
+
|
|
83
|
+
### CLI mode
|
|
84
|
+
|
|
85
|
+
You can call `lazycommit` directly to generate a commit message for your staged changes:
|
|
86
|
+
|
|
87
|
+
```sh
|
|
88
|
+
git add <files...>
|
|
89
|
+
lazycommit
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
`lazycommit` passes down unknown flags to `git commit`, so you can pass in [`commit` flags](https://git-scm.com/docs/git-commit).
|
|
93
|
+
|
|
94
|
+
For example, you can stage all changes in tracked files as you commit:
|
|
95
|
+
|
|
96
|
+
```sh
|
|
97
|
+
lazycommit --all # or -a
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
> 👉 **Tip:** Use the `lzc` alias if `lazycommit` is too long for you.
|
|
101
|
+
|
|
102
|
+
#### Generate multiple recommendations
|
|
103
|
+
|
|
104
|
+
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:
|
|
105
|
+
|
|
106
|
+
```sh
|
|
107
|
+
lazycommit --generate <i> # or -g <i>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
> Warning: this uses more tokens, meaning it costs more.
|
|
111
|
+
|
|
112
|
+
#### Generating Conventional Commits
|
|
113
|
+
|
|
114
|
+
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:
|
|
115
|
+
|
|
116
|
+
```sh
|
|
117
|
+
lazycommit --type conventional # or -t conventional
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
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.
|
|
121
|
+
|
|
122
|
+
#### Review, edit, and confirm messages
|
|
123
|
+
|
|
124
|
+
Lazycommit now lets you review the generated message, optionally edit it, and then confirm before it is committed.
|
|
125
|
+
|
|
126
|
+
- You'll see a menu: Use as-is, Edit, or Cancel
|
|
127
|
+
- If you choose Use as-is, it commits immediately without additional prompts
|
|
128
|
+
- If you choose Edit, you can modify the message; then you'll be asked to confirm the final message before committing
|
|
129
|
+
|
|
130
|
+
Example (single commit):
|
|
131
|
+
|
|
132
|
+
```sh
|
|
133
|
+
git add .
|
|
134
|
+
lazycommit
|
|
135
|
+
# Review generated commit message:
|
|
136
|
+
# feat: add lazycommit command
|
|
137
|
+
# → Choose "Use as-is" to commit immediately
|
|
138
|
+
# → Or choose "Edit" to modify, then confirm the final message before commit
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
#### Exclude files from analysis
|
|
142
|
+
|
|
143
|
+
You can exclude specific files from AI analysis using the `--exclude` flag:
|
|
144
|
+
|
|
145
|
+
```sh
|
|
146
|
+
lazycommit --exclude package-lock.json --exclude dist/
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
#### Handling large diffs
|
|
150
|
+
|
|
151
|
+
For large commits with many files, lazycommit automatically stays within API limits and generates relevant commit messages:
|
|
152
|
+
|
|
153
|
+
- **Smart summarization**: Uses `git diff --cached --numstat` to create compact summaries of all changes
|
|
154
|
+
- **Context snippets**: Includes truncated diff snippets from top changed files for better context
|
|
155
|
+
- **Token-safe processing**: Keeps prompts small while maintaining accuracy for 20+ file changes
|
|
156
|
+
- **Single commit**: Always generates one commit message, no matter how many files are staged
|
|
157
|
+
- **Enhanced analysis**: Uses improved prompts and smart truncation for better commit message quality
|
|
158
|
+
|
|
159
|
+
### Git hook
|
|
160
|
+
|
|
161
|
+
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. The hook uses the same enhanced analysis and quality improvements as the CLI mode.
|
|
162
|
+
|
|
163
|
+
#### Install
|
|
164
|
+
|
|
165
|
+
In the Git repository you want to install the hook in:
|
|
166
|
+
|
|
167
|
+
```sh
|
|
168
|
+
lazycommit hook install
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
#### Uninstall
|
|
172
|
+
|
|
173
|
+
In the Git repository you want to uninstall the hook from:
|
|
174
|
+
|
|
175
|
+
```sh
|
|
176
|
+
lazycommit hook uninstall
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
#### Usage
|
|
180
|
+
|
|
181
|
+
1. Stage your files and commit:
|
|
182
|
+
|
|
183
|
+
```sh
|
|
184
|
+
git add <files...>
|
|
185
|
+
git commit # Only generates a message when it's not passed in
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
> If you ever want to write your own message instead of generating one, you can simply pass one in: `git commit -m "My message"`
|
|
189
|
+
|
|
190
|
+
2. Lazycommit will generate a high-quality commit message using the same enhanced analysis as the CLI mode 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.
|
|
191
|
+
|
|
192
|
+
3. Save and close the editor to commit!
|
|
193
|
+
|
|
194
|
+
## Configuration
|
|
195
|
+
|
|
196
|
+
### Guided setup (first-time)
|
|
197
|
+
|
|
198
|
+
Run:
|
|
199
|
+
|
|
200
|
+
```sh
|
|
201
|
+
lazycommit config
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
This opens a step-by-step setup flow for:
|
|
205
|
+
|
|
206
|
+
- provider
|
|
207
|
+
- provider API key
|
|
208
|
+
- model
|
|
209
|
+
- generate
|
|
210
|
+
- locale
|
|
211
|
+
- proxy
|
|
212
|
+
- timeout
|
|
213
|
+
- max-length
|
|
214
|
+
- type
|
|
215
|
+
- signup-message
|
|
216
|
+
|
|
217
|
+
At the end, lazycommit saves your config and prints the updated values.
|
|
218
|
+
|
|
219
|
+
### Interactive change mode
|
|
220
|
+
|
|
221
|
+
To update settings later through a menu:
|
|
222
|
+
|
|
223
|
+
```sh
|
|
224
|
+
lazycommit config change
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
This lists all editable settings, lets you choose one, prompts for a new value, saves it, and shows the updated config.
|
|
228
|
+
|
|
229
|
+
### Reading a configuration value
|
|
230
|
+
|
|
231
|
+
To retrieve a configuration option, use the command:
|
|
232
|
+
|
|
233
|
+
```sh
|
|
234
|
+
lazycommit config get <key>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
For example, to retrieve the API key, you can use:
|
|
238
|
+
|
|
239
|
+
```sh
|
|
240
|
+
lazycommit config get GROQ_API_KEY
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
You can also retrieve multiple configuration options at once by separating them with spaces:
|
|
244
|
+
|
|
245
|
+
```sh
|
|
246
|
+
lazycommit config get GROQ_API_KEY generate
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
To display all current configuration settings in a readable format, use:
|
|
250
|
+
|
|
251
|
+
```sh
|
|
252
|
+
lazycommit config show
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Setting a configuration value
|
|
256
|
+
|
|
257
|
+
To set a configuration option, use the command:
|
|
258
|
+
|
|
259
|
+
```sh
|
|
260
|
+
lazycommit config set <key>=<value>
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
For example, to set the API key, you can use:
|
|
264
|
+
|
|
265
|
+
```sh
|
|
266
|
+
lazycommit config set GROQ_API_KEY=<your-api-key>
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
You can also set multiple configuration options at once by separating them with spaces, like
|
|
270
|
+
|
|
271
|
+
```sh
|
|
272
|
+
lazycommit config set GROQ_API_KEY=<your-api-key> generate=3 locale=en
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### Options
|
|
276
|
+
|
|
277
|
+
#### GROQ_API_KEY
|
|
278
|
+
|
|
279
|
+
Required
|
|
280
|
+
|
|
281
|
+
The Groq API key. You can retrieve it from [Groq Console](https://console.groq.com/keys).
|
|
282
|
+
|
|
283
|
+
#### provider
|
|
284
|
+
|
|
285
|
+
Default: `groq`
|
|
286
|
+
|
|
287
|
+
Provider used to generate commit messages.
|
|
288
|
+
|
|
289
|
+
Supported values:
|
|
290
|
+
|
|
291
|
+
- `groq`
|
|
292
|
+
- `github`
|
|
293
|
+
|
|
294
|
+
Examples:
|
|
295
|
+
|
|
296
|
+
```sh
|
|
297
|
+
lazycommit config set provider=github
|
|
298
|
+
lazycommit config set provider=groq
|
|
299
|
+
```
|
|
300
|
+
|
|
301
|
+
When switching providers, lazycommit automatically resets `model` to that provider's default if the current model is incompatible.
|
|
302
|
+
|
|
303
|
+
#### locale
|
|
304
|
+
|
|
305
|
+
Default: `en`
|
|
306
|
+
|
|
307
|
+
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.
|
|
308
|
+
|
|
309
|
+
#### generate
|
|
310
|
+
|
|
311
|
+
Default: `1`
|
|
312
|
+
|
|
313
|
+
The number of commit messages to generate to pick from.
|
|
314
|
+
|
|
315
|
+
Note, this will use more tokens as it generates more results.
|
|
316
|
+
|
|
317
|
+
#### proxy
|
|
318
|
+
|
|
319
|
+
Set a HTTP/HTTPS proxy to use for requests.
|
|
320
|
+
|
|
321
|
+
To clear the proxy option, you can use the command (note the empty value after the equals sign):
|
|
322
|
+
|
|
323
|
+
```sh
|
|
324
|
+
lazycommit config set proxy=
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
#### model
|
|
328
|
+
|
|
329
|
+
Default: depends on `provider`
|
|
330
|
+
|
|
331
|
+
The model to use for generating commit messages.
|
|
332
|
+
|
|
333
|
+
Available models by provider:
|
|
334
|
+
|
|
335
|
+
- `groq`:
|
|
336
|
+
- `openai/gpt-oss-120b` (default)
|
|
337
|
+
- `moonshotai/kimi-k2-instruct-0905`
|
|
338
|
+
- `moonshotai/kimi-k2-instruct`
|
|
339
|
+
- `groq/compound`
|
|
340
|
+
- `groq/compound-mini`
|
|
341
|
+
- `github`:
|
|
342
|
+
- `gpt-5-mini` (default)
|
|
343
|
+
- `gpt-5.4-mini`
|
|
344
|
+
|
|
345
|
+
Example:
|
|
346
|
+
|
|
347
|
+
```sh
|
|
348
|
+
lazycommit config set provider=github model=gpt-5.4-mini
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
#### timeout
|
|
352
|
+
|
|
353
|
+
The timeout for network requests to the Groq API in milliseconds.
|
|
354
|
+
|
|
355
|
+
Default: `1000` (1 second)
|
|
356
|
+
|
|
357
|
+
```sh
|
|
358
|
+
lazycommit config set timeout=20000 # 20s
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
#### max-length
|
|
362
|
+
|
|
363
|
+
The maximum character length of the generated commit message.
|
|
364
|
+
|
|
365
|
+
Default: `100`
|
|
366
|
+
|
|
367
|
+
```sh
|
|
368
|
+
lazycommit config set max-length=150
|
|
369
|
+
```
|
|
370
|
+
|
|
371
|
+
#### type
|
|
372
|
+
|
|
373
|
+
Default: `""` (Empty string)
|
|
374
|
+
|
|
375
|
+
The type of commit message to generate. Set this to "conventional" to generate commit messages that follow the Conventional Commits specification:
|
|
376
|
+
|
|
377
|
+
```sh
|
|
378
|
+
lazycommit config set type=conventional
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
You can clear this option by setting it to an empty string:
|
|
382
|
+
|
|
383
|
+
```sh
|
|
384
|
+
lazycommit config set type=
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
#### signup-message
|
|
388
|
+
|
|
389
|
+
Default: `""` (Empty string)
|
|
390
|
+
|
|
391
|
+
Optional sign-off identity to append at the end of generated messages.
|
|
392
|
+
|
|
393
|
+
If set, lazycommit instructs the AI to end with:
|
|
394
|
+
|
|
395
|
+
```text
|
|
396
|
+
--
|
|
397
|
+
Signed-off-by: <signup-message>
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
Example:
|
|
401
|
+
|
|
402
|
+
```sh
|
|
403
|
+
lazycommit config set signup-message="Sachin Thapa <contactsachin572@gmail.com>"
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
## How it works
|
|
407
|
+
|
|
408
|
+
This CLI tool runs `git diff` to grab all your latest code changes, then sends them to the configured provider model and returns AI-generated commit messages.
|
|
409
|
+
|
|
410
|
+
Provider behavior:
|
|
411
|
+
|
|
412
|
+
- `groq` uses Groq API with `GROQ_API_KEY`
|
|
413
|
+
- `github` uses GitHub Copilot SDK and your local Copilot CLI login session
|
|
414
|
+
|
|
415
|
+
### Large diff handling
|
|
416
|
+
|
|
417
|
+
For large commits that exceed API token limits, lazycommit automatically:
|
|
418
|
+
|
|
419
|
+
1. **Detects large/many-file diffs** and switches to enhanced analysis mode
|
|
420
|
+
2. **Creates compact summaries** using `git diff --cached --numstat` to capture all changes efficiently
|
|
421
|
+
3. **Includes context snippets** from the most changed files to provide semantic context
|
|
422
|
+
4. **Generates a single commit message** that accurately reflects all changes without hitting API limits
|
|
423
|
+
5. **Smart truncation** preserves sentence structure and meaning when messages approach length limits
|
|
424
|
+
6. **Enhanced prompts** provide better context for AI to generate complete, professional commit messages
|
|
425
|
+
|
|
426
|
+
This ensures you can commit large changes (like new features, refactoring, or initial project setup) without hitting API limits, while maintaining accuracy, relevance, and high-quality commit messages.
|
|
427
|
+
|
|
428
|
+
## Troubleshooting
|
|
429
|
+
|
|
430
|
+
### "Request too large" error (413)
|
|
431
|
+
|
|
432
|
+
If you get a 413 error, your diff is too large for the API. Try these solutions:
|
|
433
|
+
|
|
434
|
+
1. **Exclude build artifacts**:
|
|
435
|
+
|
|
436
|
+
```sh
|
|
437
|
+
lazycommit --exclude "dist/**" --exclude "node_modules/**" --exclude ".next/**"
|
|
438
|
+
```
|
|
439
|
+
|
|
440
|
+
2. **Use a different model**:
|
|
441
|
+
|
|
442
|
+
```sh
|
|
443
|
+
lazycommit config set model "groq/compound-mini"
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
3. **Commit in smaller batches**:
|
|
447
|
+
```sh
|
|
448
|
+
git add src/ # Stage only source files
|
|
449
|
+
lazycommit
|
|
450
|
+
git add docs/ # Then stage documentation
|
|
451
|
+
lazycommit
|
|
452
|
+
```
|
|
453
|
+
|
|
454
|
+
### No commit messages generated
|
|
455
|
+
|
|
456
|
+
- Check provider settings: `lazycommit config show`
|
|
457
|
+
- For `groq`, verify `GROQ_API_KEY` is set
|
|
458
|
+
- For `github`, run `copilot auth login`
|
|
459
|
+
- Verify you have staged changes: `git status`
|
|
460
|
+
- Try excluding large files or using a different model
|
|
461
|
+
|
|
462
|
+
### Slow performance with large diffs
|
|
463
|
+
|
|
464
|
+
- **Use the default model**: `lazycommit config set model "openai/gpt-oss-120b"`
|
|
465
|
+
- Exclude unnecessary files: `lazycommit --exclude "*.log" --exclude "*.tmp"`
|
|
466
|
+
- Use the built-in large diff handling for better context and accuracy
|
|
467
|
+
- Lower generate count: `lazycommit config set generate=1` (default)
|
|
468
|
+
- Reduce timeout: `lazycommit config set timeout=5000` for faster failures
|
|
469
|
+
|
|
470
|
+
## Why Groq?
|
|
471
|
+
|
|
472
|
+
- **Fast**: Groq provides ultra-fast inference speeds, especially with the 8B instant model
|
|
473
|
+
- **Cost-effective**: More affordable than traditional AI APIs
|
|
474
|
+
- **Open source models**: Uses leading open-source language models
|
|
475
|
+
- **Reliable**: High uptime and consistent performance
|
|
476
|
+
- **Optimized for commits**: The 8B instant model is perfectly sized for conventional commit generation
|
|
477
|
+
|
|
478
|
+
## Maintainers
|
|
479
|
+
|
|
480
|
+
- **Kartik Labhshetwar**: [@KartikLabhshetwar](https://github.com/KartikLabhshetwar)
|
|
481
|
+
|
|
482
|
+
## Contributing
|
|
483
|
+
|
|
484
|
+
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.
|
|
485
|
+
|
|
486
|
+
## License
|
|
487
|
+
|
|
488
|
+
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,168 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
var it=Object.defineProperty;var r=(e,t)=>it(e,"name",{value:t,configurable:!0});import{command as fe,cli as at}from"cleye";import{readFileSync as rt}from"fs";import{fileURLToPath as pe,pathToFileURL as ut}from"url";import te,{dirname as ct,join as lt}from"path";import{intro as G,spinner as ne,select as K,isCancel as M,outro as v,text as P,confirm as oe}from"@clack/prompts";import{execa as I}from"execa";import{dim as L,bgCyan as he,black as ye,green as z,red as W}from"kolorist";import x from"fs/promises";import we from"ini";import mt from"os";import{CopilotClient as dt,approveAll as gt}from"@github/copilot-sdk";import ve from"groq-sdk";var ft="1.0.0",pt={version:ft};const de=class de extends Error{};r(de,"KnownError");let p=de;const se=" ",Y=r(e=>{e instanceof Error&&!(e instanceof p)&&(e.stack&&console.error(L(e.stack.split(`
|
|
3
|
+
`).slice(1).join(`
|
|
4
|
+
`))),console.error(`
|
|
5
|
+
${se}${L(`lazycommit v${pt.version}`)}`),console.error(`
|
|
6
|
+
${se}Please open a Bug report with the information above:`),console.error(`${se}https://github.com/KartikLabhshetwar/lazycommit/issues/new/choose`))},"handleCliError"),be=r(e=>x.lstat(e).then(()=>!0,()=>!1),"fileExists"),ht=["","conventional"],H=["groq","github"],O={groq:{label:"Groq",authMode:"api-key",apiKeyConfigKey:"GROQ_API_KEY",missingAuthMessage:"Please set your Groq API key via `lazycommit config set GROQ_API_KEY=<your token>`",apiKeyPrefix:"gsk_"},github:{label:"GitHub Copilot",authMode:"copilot",missingAuthMessage:"Please login to GitHub Copilot CLI first via `copilot auth login`, then try again."}},N={groq:["openai/gpt-oss-120b","moonshotai/kimi-k2-instruct-0905","moonshotai/kimi-k2-instruct","groq/compound","groq/compound-mini"],github:["gpt-5-mini","gpt-5.4-mini","gpt-4o-mini-2024-07-18"]},q="groq",ie=N[q][0],yt=H,wt=q,$e=ie,Ce=H.map(e=>{const t=O[e];if(t.authMode==="api-key")return t.apiKeyConfigKey}).filter(e=>!!e),ae=r(e=>O[e].label,"getProviderLabel"),j=r(e=>O[e].authMode==="api-key","providerRequiresApiKey"),Me=r(e=>N[e][0],"getDefaultModelForProvider"),R=r(e=>{const t=O[e];if(t.authMode==="api-key")return t.apiKeyConfigKey},"getProviderApiKeyConfigKey"),vt=r(e=>N[e],"getModelsForProvider"),xe=r(e=>O[e].missingAuthMessage,"getProviderMissingAuthMessage"),bt=r((e,t)=>N[e].includes(t),"isProviderModel"),$t=r((e,t)=>`Model "${t}" is not available for provider "${e}". Must be one of: ${N[e].join(", ")}`,"providerModelValidationMessage"),Ae=r((e,t,n)=>{if(bt(e,t))return t;if(n)return Me(e);throw new p(`Invalid config property model: ${$t(e,t)}`)},"resolveModelForProvider"),B=r(e=>{if(!e)return;const t=e.trim();return t.length>0?t:void 0},"normalizeApiKey"),ke=r(e=>e.length<=8?"****":`${e.slice(0,4)}...${e.slice(-4)}`,"maskApiKey"),Se=r(e=>{const t=e.https_proxy||e.HTTPS_PROXY||e.http_proxy||e.HTTP_PROXY;if(!t)return;const n=t.trim();if(n)return/^https?:\/\//.test(n)?n:void 0},"getProxyFromEnv"),{hasOwnProperty:Ct}=Object.prototype,Pe=r((e,t)=>Ct.call(e,t),"hasOwn"),$=r((e,t,n)=>{if(!t)throw new p(`Invalid config property ${e}: ${n}`)},"parseAssert"),_={provider(e){return!e||e.length===0?q:($("provider",H.includes(e),`Must be one of: ${H.join(", ")}`),e)},GROQ_API_KEY(e){if(e)return $("GROQ_API_KEY",e.startsWith(O.groq.apiKeyPrefix),`Must start with "${O.groq.apiKeyPrefix}"`),e},locale(e){return e?($("locale",e,"Cannot be empty"),$("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;$("generate",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return $("generate",t>0,"Must be greater than 0"),$("generate",t<=5,"Must be less or equal to 5"),t},type(e){return e?($("type",ht.includes(e),"Invalid commit type"),e):""},proxy(e){const t=e?.trim();if(!(!t||t.length===0)&&!(t==="undefined"||t==="null"))return $("proxy",/^https?:\/\//.test(t),"Must be a valid URL"),t},model(e){if(!e||e.length===0)return ie;const t=Object.values(N).flat();return $("model",t.includes(e),`Must be one of: ${t.join(", ")}`),e},timeout(e){if(!e)return 1e3;$("timeout",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return $("timeout",t>=500,"Must be greater than 500ms"),t},"max-length"(e){if(!e)return 100;$("max-length",/^\d+$/.test(e),"Must be an integer");const t=Number(e);return $("max-length",t>=20,"Must be greater than 20 characters"),$("max-length",t<=200,"Must be less than or equal to 200 characters"),t},"signup-message"(e){return e?e.trim():""}},Ie=r(e=>{const t=e.provider||q;if(!j(t))return;const n=R(t);if(!(n?e[n]:void 0))throw new p(xe(t))},"assertProviderRequirements"),Ee=r(e=>{if(!j(e.provider))return;Ie(e);const t=R(e.provider);return t?String(e[t]):void 0},"getProviderApiKey"),re=te.join(mt.homedir(),".lazycommit"),Oe=r(async()=>{if(!await be(re))return Object.create(null);const t=await x.readFile(re,"utf8");return we.parse(t)},"readConfigFile"),E=r(async(e,t)=>{const n=await Oe(),o={};for(const i of Object.keys(_)){const u=_[i],l=e?.[i]??n[i];if(t)try{o[i]=u(l)}catch{}else o[i]=u(l)}const s=o.provider||q;o.provider=s;const a=String(o.model||ie);return o.model=Ae(s,a,!!t),t||Ie(o),o},"getConfig"),ue=r(async e=>{const t=await Oe(),n=new Set;for(const[u,l]of e){if(!Pe(_,u))throw new p(`Invalid config property: ${u}`);n.add(u);const m=_[u](l);m===void 0?delete t[u]:t[u]=m}const o=_.provider(t.provider);t.provider=o;const s=_.model(t.model),a=n.has("provider"),i=n.has("model");t.model=Ae(o,s,a&&!i),await x.writeFile(re,we.stringify(t),"utf8")},"setConfigs"),De=r(async()=>{const{stdout:e,failed:t}=await I("git",["rev-parse","--show-toplevel"],{reject:!1});if(t)throw new p("The current directory must be a Git repository!");return e},"assertGitRepo"),V=r(e=>`:(exclude)${e}`,"excludeFromDiff"),ce=["package-lock.json","node_modules/**","dist/**","build/**",".next/**","coverage/**",".nyc_output/**","*.log","*.tmp","*.temp","*.cache",".DS_Store","Thumbs.db","*.min.js","*.min.css","*.bundle.js","*.bundle.css","*.lock"].map(V),Te=r(async e=>{const t=["diff","--cached","--diff-algorithm=minimal"],{stdout:n}=await I("git",[...t,"--name-only",...ce,...e?e.map(V):[]]);if(!n)return;const{stdout:o}=await I("git",[...t,...ce,...e?e.map(V):[]]);return{files:n.split(`
|
|
7
|
+
`),diff:o}},"getStagedDiff"),Ke=r(e=>`Detected ${e.length.toLocaleString()} staged file${e.length>1?"s":""}`,"getDetectedMessage"),Ne=r(async e=>{const t=["diff","--cached","--diff-algorithm=minimal"],{stdout:n}=await I("git",[...t,"--name-only",...ce,...e?e.map(V):[]]);if(!n)return null;const o=n.split(`
|
|
8
|
+
`).filter(Boolean),s=await Promise.all(o.map(async a=>{try{const{stdout:i}=await I("git",[...t,"--numstat","--",a]),[u,l]=i.split(" ").slice(0,2).map(Number);return{file:a,additions:u||0,deletions:l||0,changes:(u||0)+(l||0)}}catch{return{file:a,additions:0,deletions:0,changes:0}}}));return{files:o,fileStats:s,totalChanges:s.reduce((a,i)=>a+i.changes,0)}},"getDiffSummary"),je=r(async(e,t=20)=>{const n=await Ne(e);if(!n)return null;const{fileStats:o}=n,s=[...o].sort((c,h)=>h.changes-c.changes),a=s.slice(0,Math.max(1,t)),i=n.files.length,u=n.totalChanges,l=o.reduce((c,h)=>c+(h.additions||0),0),m=o.reduce((c,h)=>c+(h.deletions||0),0),d=[];d.push(`Files changed: ${i}`),d.push(`Additions: ${l}, Deletions: ${m}, Total changes: ${u}`),d.push("Top files by changes:");for(const c of a)d.push(`- ${c.file} (+${c.additions} / -${c.deletions}, ${c.changes} changes)`);return s.length>a.length&&d.push(`\u2026and ${s.length-a.length} more files`),d.join(`
|
|
9
|
+
`)},"buildCompactSummary"),Mt={"":"<commit message>",conventional:"<type>(<optional scope>): <commit message>"},Re={"":"",conventional:`Choose the most appropriate type from the following categories that best describes the git diff:
|
|
10
|
+
|
|
11
|
+
${JSON.stringify({feat:"A NEW user-facing feature or functionality that adds capabilities",fix:"A bug fix that resolves an existing issue",docs:"Documentation only changes (README, comments, etc)",style:"Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)",refactor:"Code restructuring, improvements, or internal changes that enhance existing functionality",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:"Maintenance tasks, config updates, dependency updates, or internal tooling changes",revert:"Reverts a previous commit"},null,2)}
|
|
12
|
+
|
|
13
|
+
IMPORTANT:
|
|
14
|
+
- Use 'feat' ONLY for NEW user-facing features
|
|
15
|
+
- Use 'refactor' for code improvements, restructuring, or internal changes
|
|
16
|
+
- Use 'chore' for config updates, maintenance, or internal tooling
|
|
17
|
+
- Use the exact type name from the list above.`},_e=r((e,t,n)=>`You are a professional git commit message generator. Generate ONLY conventional commit messages.
|
|
18
|
+
|
|
19
|
+
CRITICAL RULES:
|
|
20
|
+
- Return ONLY the commit message line, nothing else
|
|
21
|
+
- Use format: type: subject (NO scope, just type and subject)
|
|
22
|
+
- Maximum ${t} characters (be concise but complete)
|
|
23
|
+
- Imperative mood, present tense
|
|
24
|
+
- Be specific and descriptive
|
|
25
|
+
- NO explanations, questions, or meta-commentary
|
|
26
|
+
- ALWAYS complete the message - never truncate mid-sentence
|
|
27
|
+
|
|
28
|
+
COMMIT TYPES:
|
|
29
|
+
- feat: NEW user-facing feature or functionality
|
|
30
|
+
- fix: bug fix that resolves an issue
|
|
31
|
+
- docs: documentation changes only
|
|
32
|
+
- style: formatting, no logic change
|
|
33
|
+
- refactor: code restructuring, improvements, or internal changes
|
|
34
|
+
- perf: performance improvements
|
|
35
|
+
- test: adding/updating tests
|
|
36
|
+
- build: build system changes
|
|
37
|
+
- ci: CI/CD changes
|
|
38
|
+
- chore: maintenance tasks, dependencies, config updates
|
|
39
|
+
|
|
40
|
+
QUALITY GUIDELINES:
|
|
41
|
+
- Start with the most important change
|
|
42
|
+
- Use specific, descriptive language
|
|
43
|
+
- Include the main component/area affected
|
|
44
|
+
- Be clear about what was done, not just what files changed
|
|
45
|
+
- Use proper grammar and punctuation
|
|
46
|
+
|
|
47
|
+
EXAMPLES (correct format - NO scope, just type and subject):
|
|
48
|
+
- feat: add user login with OAuth integration
|
|
49
|
+
- fix: resolve memory leak in image processing service
|
|
50
|
+
- refactor: improve message generation with better prompts
|
|
51
|
+
- refactor: increase default max-length from 50 to 100
|
|
52
|
+
- docs: update installation and configuration guide
|
|
53
|
+
- test: add unit tests for JWT token validation
|
|
54
|
+
- chore: update axios to v1.6.0 for security patches
|
|
55
|
+
|
|
56
|
+
WRONG FORMAT (do not use):
|
|
57
|
+
- feat(auth): add user login
|
|
58
|
+
- refactor(commit): improve prompts
|
|
59
|
+
|
|
60
|
+
${Re[n]?`
|
|
61
|
+
DETAILED TYPE GUIDELINES:
|
|
62
|
+
${Re[n]}`:""}
|
|
63
|
+
|
|
64
|
+
Language: ${e}
|
|
65
|
+
Output format: ${Mt[n]||"type: subject"}
|
|
66
|
+
|
|
67
|
+
Generate a single, complete, professional commit message that accurately describes the changes.`,"generatePrompt"),xt=15e3,At=3e4,Le=r(e=>{const t=String(e?.message||e||"");return/timeout after\s+\d+ms\s+waiting for session\.idle/i.test(t)},"isSessionIdleTimeoutError"),kt=r(e=>{const t=e.filter(o=>o.role==="system").map(o=>o.content).join(`
|
|
68
|
+
|
|
69
|
+
`),n=e.filter(o=>o.role!=="system").map(o=>o.content).join(`
|
|
70
|
+
|
|
71
|
+
`);return t?n?`${t}
|
|
72
|
+
|
|
73
|
+
${n}`:t:n},"buildPromptFromMessages"),St=r(async(e,t,n,o)=>{const s=kt(t),a=Math.max(o,xt),i=new dt({useLoggedInUser:!0});try{const u=Array.from({length:n},async()=>{const m=r(async h=>{const y=await i.createSession({model:e,onPermissionRequest:gt,availableTools:[]});try{return await y.sendAndWait({prompt:s},h)}finally{await y.disconnect().catch(()=>{})}},"runRequest");let d;try{d=await m(a)}catch(h){if(!Le(h))throw h;const y=Math.max(At,a*2);d=await m(y)}return{message:{content:d?.data?.content||""}}});return{choices:await Promise.all(u)}}catch(u){const l=String(u?.message||u||"Unknown error");throw/copilot(\.exe)?\b.*(not found|ENOENT|spawn)/i.test(l)?new p("GitHub Copilot CLI is required for the github provider. Install it and make sure `copilot` is available in your PATH."):/auth|authenticate|login|sign in|unauthorized|forbidden|401|403/i.test(l)?new p("GitHub Copilot authentication is required. Run `copilot auth login` and try again."):Le(u)?new p("GitHub Copilot response timed out while waiting for generation to finish. Try again or increase timeout with `lazycommit config set timeout=15000`."):new p(`GitHub Copilot SDK Error: ${l}`)}finally{await i.stop().catch(()=>[])}},"createChatCompletion$1"),Pt=r(e=>e.trim().replace(/^["']|["']\.?$/g,"").replace(/[\n\r]/g,"").replace(/(\w)\.$/,"$1"),"sanitizeMessage$1"),It=r((e,t)=>{if(e.length<=t)return e;const n=e.slice(0,t),o=Math.max(n.lastIndexOf(". "),n.lastIndexOf("! "),n.lastIndexOf("? "));if(o>t*.7)return n.slice(0,o+1);const s=Math.max(n.lastIndexOf(", "),n.lastIndexOf("; "));if(s>t*.6)return n.slice(0,s+1);const a=n.lastIndexOf(" ");return a>t*.5?n.slice(0,a):e.length>t+10?`${n}...`:n},"enforceMaxLength$1"),Et=r(e=>Array.from(new Set(e)),"deduplicateMessages$1"),Ot=r(async(e,t,n,o,s,a,i,u)=>{const l=u?`
|
|
74
|
+
|
|
75
|
+
--
|
|
76
|
+
Signed-off-by: ${u}`:"",d=((await St(e,[{role:"system",content:_e(t,s,a)},{role:"user",content:n}],o,i)).choices||[]).map(c=>c.message?.content||"").map(c=>Pt(String(c))).filter(Boolean).map(c=>c.length>s*1.1?It(c,s):c).map(c=>l?`${c}${l}`:c).filter(c=>c.length>=10);return Et(d)},"generateCommitMessageFromSummary$1"),Dt=r(async(e,t,n,o,s,a,i,u,l,m)=>{const d=new ve({apiKey:e,timeout:m});try{return l>1?{choices:(await Promise.all(Array.from({length:l},()=>d.chat.completions.create({model:t,messages:n,temperature:o,top_p:s,frequency_penalty:a,presence_penalty:i,max_tokens:u,n:1})))).flatMap(y=>y.choices)}:await d.chat.completions.create({model:t,messages:n,temperature:o,top_p:s,frequency_penalty:a,presence_penalty:i,max_tokens:u,n:1})}catch(c){if(c instanceof ve.APIError){let h=`Groq API Error: ${c.status} - ${c.name}`;throw c.message&&(h+=`
|
|
77
|
+
|
|
78
|
+
${c.message}`),c.status===500&&(h+=`
|
|
79
|
+
|
|
80
|
+
Check the API status: https://console.groq.com/status`),(c.status===413||c.message&&c.message.includes("rate_limit_exceeded"))&&(h+=`
|
|
81
|
+
|
|
82
|
+
\u{1F4A1} Tip: Your diff is too large. Try:
|
|
83
|
+
1. Commit files in smaller batches
|
|
84
|
+
2. Exclude large files with --exclude
|
|
85
|
+
3. Use a different model with --model
|
|
86
|
+
4. Check if you have build artifacts staged (dist/, .next/, etc.)`),new p(h)}throw c.code==="ENOTFOUND"?new p(`Error connecting to ${c.hostname} (${c.syscall}). Are you connected to the internet?`):c}},"createChatCompletion"),qe=r(e=>e.trim().replace(/^["']|["']\.?$/g,"").replace(/[\n\r]/g,"").replace(/(\w)\.$/,"$1"),"sanitizeMessage"),Ue=r((e,t)=>{if(e.length<=t)return e;const n=e.slice(0,t),o=Math.max(n.lastIndexOf(". "),n.lastIndexOf("! "),n.lastIndexOf("? "));if(o>t*.7)return n.slice(0,o+1);const s=Math.max(n.lastIndexOf(", "),n.lastIndexOf("; "));if(s>t*.6)return n.slice(0,s+1);const a=n.lastIndexOf(" ");return a>t*.5?n.slice(0,a):e.length>t+10?n+"...":n},"enforceMaxLength"),Tt=r(e=>Array.from(new Set(e)),"deduplicateMessages"),Kt=["feat:","fix:","docs:","style:","refactor:","perf:","test:","build:","ci:","chore:","revert:"],Nt=r((e,t)=>{const n=e.replace(/\s+/g," ").trim(),o=n.match(/\b(feat|fix|docs|style|refactor|perf|test|build|ci|chore|revert)\b\s*:?\s+[^.\n]+/i);let s=o?o[0]:n.split(/[.!?]/)[0];if(!o&&s.length<10){const i=n.split(/[.!?]/).filter(u=>u.trim().length>10);i.length>0&&(s=i[0].trim())}const a=s.toLowerCase();for(const i of Kt){const u=i.slice(0,-1);if(a.startsWith(u+" ")&&!a.startsWith(i)){s=u+": "+s.slice(u.length+1);break}}return s=qe(s),!s||s.length<5?null:(s.length>t*1.2&&(s=Ue(s,t)),s)},"deriveMessageFromReasoning"),jt=r(async(e,t,n,o,s,a,i,u,l,m)=>{const d=o,c=m?`
|
|
87
|
+
|
|
88
|
+
--
|
|
89
|
+
Signed-off-by: ${m}`:"",h=await Dt(e,t,[{role:"system",content:_e(n,a,i)},{role:"user",content:d}],.3,1,0,0,Math.max(300,a*12),s,u),y=(h.choices||[]).map(g=>g.message?.content||"").map(g=>qe(g)).filter(Boolean).map(g=>g.length>a*1.1?Ue(g,a):g).map(g=>c?`${g}${c}`:g).filter(g=>g.length>=10);if(y.length>0)return Tt(y);const C=h.choices.map(g=>g.message?.reasoning||"").filter(Boolean);for(const g of C){const A=Nt(g,a);if(A)return[A]}return[]},"generateCommitMessageFromSummary"),J=r(async({provider:e,apiKey:t,model:n,locale:o,summary:s,completions:a,maxLength:i,type:u,timeout:l,proxy:m,signupMessage:d})=>{switch(e){case"groq":{if(!t)throw new p(xe(e));return jt(t,n,o,s,a,i,u,l,m,d)}case"github":return Ot(n,o,s,a,i,u,l,d);default:throw new p(`Unsupported provider: ${e}`)}},"generateCommitMessages"),Rt=r(async(e,t=30,n=4e3)=>{try{const o=e.slice(0,5),s=[];let a=n;for(const i of o){const{stdout:u}=await I("git",["diff","--cached","--unified=0","--",i]);if(!u)continue;const l=u.split(`
|
|
90
|
+
`).filter(Boolean),m=[];let d=0;for(const c of l){const h=c.startsWith("@@"),y=(c.startsWith("+")||c.startsWith("-"))&&!c.startsWith("+++")&&!c.startsWith("---");if((h||y)&&(m.push(c),d++,d>=t))break}if(m.length>0){const c=[`# ${i}`,...m].join(`
|
|
91
|
+
`);c.length<=a?(s.push(c),a-=c.length):(s.push(c.slice(0,Math.max(0,a))),a=0)}if(a<=0)break}return s.length===0?"":["Context snippets (truncated):",...s].join(`
|
|
92
|
+
`)}catch{return""}},"buildDiffSnippets"),Q=r(async(e,t,n)=>{const o=await Rt(e,30,3e3);return`Analyze the following git changes and generate a single, complete conventional commit message.
|
|
93
|
+
|
|
94
|
+
CHANGES SUMMARY:
|
|
95
|
+
${t}
|
|
96
|
+
|
|
97
|
+
${o?`
|
|
98
|
+
CODE CONTEXT:
|
|
99
|
+
${o}
|
|
100
|
+
`:""}
|
|
101
|
+
|
|
102
|
+
TASK: Write ONE conventional commit message that accurately describes what was changed.
|
|
103
|
+
|
|
104
|
+
REQUIREMENTS:
|
|
105
|
+
- Format: type: subject (NO scope, just type and subject)
|
|
106
|
+
- Maximum ${n} characters
|
|
107
|
+
- Be specific and descriptive
|
|
108
|
+
- Use imperative mood, present tense
|
|
109
|
+
- Include the main component/area affected
|
|
110
|
+
- Complete the message - never truncate mid-sentence
|
|
111
|
+
|
|
112
|
+
COMMIT TYPE GUIDELINES:
|
|
113
|
+
- feat: NEW user-facing features only
|
|
114
|
+
- refactor: code improvements, restructuring, internal changes
|
|
115
|
+
- fix: bug fixes that resolve issues
|
|
116
|
+
- docs: documentation changes only
|
|
117
|
+
- chore: config updates, maintenance, dependencies
|
|
118
|
+
|
|
119
|
+
EXAMPLES (correct format - NO scope, just type and subject):
|
|
120
|
+
- feat: add user login with OAuth integration
|
|
121
|
+
- fix: resolve memory leak in image processing service
|
|
122
|
+
- refactor: improve message generation with better prompts
|
|
123
|
+
- refactor: increase default max-length from 50 to 100
|
|
124
|
+
- docs: update installation and configuration guide
|
|
125
|
+
- test: add unit tests for JWT token validation
|
|
126
|
+
- chore: update axios to v1.6.0 for security patches
|
|
127
|
+
|
|
128
|
+
WRONG FORMAT (do not use):
|
|
129
|
+
- feat(auth): add user login
|
|
130
|
+
- refactor(commit): improve prompts
|
|
131
|
+
|
|
132
|
+
Return only the commit message line, no explanations.`},"buildSingleCommitPrompt"),_t=`\u2554\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2557
|
|
133
|
+
\u2502 \u2502
|
|
134
|
+
\u2502 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2557 \u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2557\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2502
|
|
135
|
+
\u2502 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557\u255A\u2550\u2550\u2588\u2588\u2588\u2554\u255D\u255A\u2588\u2588\u2557 \u2588\u2588\u2554\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D\u2588\u2588\u2554\u2550\u2550\u2550\u2588\u2588\u2557\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2550\u2550\u2588\u2588\u2554\u2550\u2550\u255D \u2502
|
|
136
|
+
\u2502 \u2588\u2588\u2551 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551 \u2588\u2588\u2588\u2554\u255D \u255A\u2588\u2588\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2554\u2588\u2588\u2588\u2588\u2554\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2502
|
|
137
|
+
\u2502 \u2588\u2588\u2551 \u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551 \u2588\u2588\u2588\u2554\u255D \u255A\u2588\u2588\u2554\u255D \u2588\u2588\u2551 \u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551\u255A\u2588\u2588\u2554\u255D\u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2502
|
|
138
|
+
\u2502 \u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u2588\u2588\u2551 \u2588\u2588\u2551\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551 \u255A\u2550\u255D \u2588\u2588\u2551\u2588\u2588\u2551 \u2588\u2588\u2551 \u2502
|
|
139
|
+
\u2502 \u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u2550\u2550\u2550\u2550\u255D \u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D\u255A\u2550\u255D \u255A\u2550\u255D \u2502
|
|
140
|
+
\u2502 \u2502
|
|
141
|
+
\u255A\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u255D`;var Lt=r(async(e,t,n,o,s,a)=>(async()=>{console.log(_t),console.log(),G(he(ye(" lazycommit "))),await De();const i=ne();n&&await I("git",["add","--update"]),i.start("Detecting staged files");const u=await Te(t);if(!u)throw i.stop("Detecting staged files"),new p("No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` flag.");const l=await Ne(t),m=u.diff.length>5e4,d=u.files.length>=5,c=l&&l.fileStats.some(f=>f.changes>500);if((m||d||c)&&l){let f="Large diff detected";d?f="Many files detected":c&&(f="Large file changes detected"),i.stop(`${Ke(u.files)} (${l.totalChanges.toLocaleString()} changes):
|
|
142
|
+
${u.files.map(b=>` ${b}`).join(`
|
|
143
|
+
`)}
|
|
144
|
+
|
|
145
|
+
${f} - using enhanced analysis for better commit message`)}else i.stop(`${Ke(u.files)}:
|
|
146
|
+
${u.files.map(f=>` ${f}`).join(`
|
|
147
|
+
`)}`);const{env:y}=process,C=await E({},!0),g=R(C.provider),A={proxy:Se(y),generate:e?.toString(),type:o?.toString()};let Z;if(j(C.provider)&&g){const f=B(String(C[g]||"")),b=B(y[g]),S=f?void 0:b;A[g]=S,Z=f?"config file":"environment"}const w=await E(A),U=Ee(w);y.LAZYCOMMIT_DEBUG==="1"&&g&&U&&Z&&console.log(L(`Debug: using ${g} from ${Z} (${ke(U)})`));const ge=ne();ge.start("The AI is analyzing your changes");let T;try{const f=await je(t,25);if(f){const b=await Q(u.files,f,w["max-length"]);T=await J({provider:w.provider,apiKey:U,model:w.model,locale:w.locale,summary:b,completions:w.generate,maxLength:w["max-length"],type:w.type,timeout:w.timeout,proxy:w.proxy,signupMessage:w["signup-message"]})}else{const b=u.files.join(", "),S=await Q(u.files,`Files: ${b}`,w["max-length"]);T=await J({provider:w.provider,apiKey:U,model:w.model,locale:w.locale,summary:S,completions:w.generate,maxLength:w["max-length"],type:w.type,timeout:w.timeout,proxy:w.proxy,signupMessage:w["signup-message"]})}}finally{ge.stop("Changes analyzed")}if(T.length===0)throw new p("No commit messages were generated. Try again.");let k,ee=!1,F=!1;if(T.length===1){[k]=T;const f=await K({message:`Review generated commit message:
|
|
148
|
+
|
|
149
|
+
${k}
|
|
150
|
+
`,options:[{label:"Use as-is",value:"use"},{label:"Edit",value:"edit"},{label:"Cancel",value:"cancel"}]});if(M(f)||f==="cancel"){v("Commit cancelled");return}if(f==="use")F=!0;else if(f==="edit"){const b=await P({message:"Edit commit message:",initialValue:k,validate:r(S=>S&&S.trim().length>0?void 0:"Message cannot be empty","validate")});if(M(b)){v("Commit cancelled");return}k=String(b).trim(),ee=!0}}else{const f=await K({message:`Pick a commit message to use: ${L("(Ctrl+c to exit)")}`,options:T.map(b=>({label:b,value:b}))});if(M(f)){v("Commit cancelled");return}k=f,F=!0}if(!F&&!ee){const f=await oe({message:"Edit the commit message before committing?"});if(f&&!M(f)){const b=await P({message:"Edit commit message:",initialValue:k,validate:r(S=>S&&S.trim().length>0?void 0:"Message cannot be empty","validate")});if(M(b)){v("Commit cancelled");return}k=String(b).trim(),ee=!0}}if(!F){const f=await oe({message:`Proceed with this commit message?
|
|
151
|
+
|
|
152
|
+
${k}
|
|
153
|
+
`});if(!f||M(f)){v("Commit cancelled");return}}await I("git",["commit","-m",k,...a]),v(`${z("\u2714")} Successfully committed!`)})().catch(i=>{v(`${W("\u2716")} ${i.message}`),Y(i),process.exit(1)}),"lazycommit");const[le,qt]=process.argv.slice(2);var Ut=r(()=>(async()=>{if(!le)throw new p('Commit message file path is missing. This file should be called from the "prepare-commit-msg" git hook');if(qt)return;const e=await Te();if(!e)return;G(he(ye(" lazycommit ")));const{env:t}=process,n=await E({},!0),o=R(n.provider),s={proxy:Se(t)};let a;if(j(n.provider)&&o){const C=B(String(n[o]||"")),g=B(t[o]),A=C?void 0:g;s[o]=A,a=C?"config file":"environment"}const i=await E(s),u=Ee(i);t.LAZYCOMMIT_DEBUG==="1"&&o&&u&&a&&console.log(L(`Debug: using ${o} from ${a} (${ke(u)})`));const l=ne();l.start("The AI is analyzing your changes");let m;try{const C=await je();if(C){const g=await Q(e.files,C,i["max-length"]);m=await J({provider:i.provider,apiKey:u,model:i.model,locale:i.locale,summary:g,completions:i.generate,maxLength:i["max-length"],type:i.type,timeout:i.timeout,proxy:i.proxy,signupMessage:i["signup-message"]})}else{const g=e.files.join(", "),A=await Q(e.files,`Files: ${g}`,i["max-length"]);m=await J({provider:i.provider,apiKey:u,model:i.model,locale:i.locale,summary:A,completions:i.generate,maxLength:i["max-length"],type:i.type,timeout:i.timeout,proxy:i.proxy,signupMessage:i["signup-message"]})}}finally{l.stop("Changes analyzed")}const c=await x.readFile(le,"utf8")!=="",h=m.length>1;let y="";c&&(y=`# \u{1F916} AI generated commit${h?"s":""}
|
|
154
|
+
`),h?(c&&(y+=`# Select one of the following messages by uncommeting:
|
|
155
|
+
`),y+=`
|
|
156
|
+
${m.map(C=>`# ${C}`).join(`
|
|
157
|
+
`)}`):(c&&(y+=`# Edit the message below and commit:
|
|
158
|
+
`),y+=`
|
|
159
|
+
${m[0]}
|
|
160
|
+
`),await x.appendFile(le,y),v(`${z("\u2714")} Saved commit message!`)})().catch(e=>{v(`${W("\u2716")} ${e.message}`),Y(e),process.exit(1)}),"prepareCommitMessageHook");const Fe=r(e=>["provider",...Ce,"model","generate","locale","proxy","timeout","max-length","type","signup-message"].map(o=>{const s=e[o];return s==null?`${o}=`:`${o}=${String(s)}`}).join(`
|
|
161
|
+
`),"formatConfigForOutput"),Ft=r(e=>{const t=["provider",...Ce,"model","generate","locale","proxy","timeout","max-length","type","signup-message"],n=Math.max(...t.map(s=>String(s).length));return["Current configuration:",...t.map(s=>{const a=e[s],i=String(s).padEnd(n," "),u=a==null||a===""?"(empty)":String(a);return`${i} : ${u}`})].join(`
|
|
162
|
+
`)},"formatConfigForDisplay"),D=r(e=>M(e)?null:e==null?"":String(e).trim(),"parseTextResult"),Ge=r(async(e=wt)=>{const t=await K({message:"Select provider",options:yt.map(n=>({label:ae(n),value:n,hint:n==="groq"?"Requires GROQ_API_KEY":"Uses GitHub Copilot CLI login"})),initialValue:e});return M(t)?null:String(t)},"askProvider"),ze=r(async(e,t="")=>{const n=ae(e),o=e==="groq"?"gsk_...":"",s=await P({message:`Enter API key for ${n}`,placeholder:o,initialValue:t,validate:r(a=>{if(!a||a.trim().length===0)return"API key is required";if(e==="groq"&&!a.startsWith("gsk_"))return"Groq API key must start with gsk_"},"validate")});return D(s)},"askApiKey"),We=r(async(e,t)=>{const n=vt(e),o=t||n[0]||$e,s=await K({message:"Select default model",options:n.map(a=>({label:a,value:a})),initialValue:o});return M(s)?null:String(s)},"askModel"),Ye=r(async e=>{const t=await P({message:"Generate count (1-5)",initialValue:String(e),validate:r(n=>{if(!/^\d+$/.test(n))return"Must be an integer";const o=Number(n);if(o<1||o>5)return"Must be between 1 and 5"},"validate")});return D(t)},"askGenerate"),He=r(async e=>{const t=await P({message:"Locale",initialValue:e,placeholder:"en",validate:r(n=>{if(!n||n.trim().length===0)return"Locale cannot be empty";if(!/^[a-z-]+$/i.test(n))return"Use letters and dashes only (example: en, en-us)"},"validate")});return D(t)},"askLocale"),Be=r(async e=>{const t=await P({message:"Proxy URL (leave empty to clear)",initialValue:e||"",validate:r(n=>{if(!(!n||n.trim().length===0)&&!/^https?:\/\//.test(n))return"Must start with http:// or https://"},"validate")});return M(t)?null:D(t)},"askProxy"),Ve=r(async e=>{const t=await P({message:"Timeout (ms)",initialValue:String(e),validate:r(n=>{if(!/^\d+$/.test(n))return"Must be an integer";if(Number(n)<500)return"Must be greater than 500ms"},"validate")});return D(t)},"askTimeout"),Je=r(async e=>{const t=await P({message:"Max commit message length (20-200)",initialValue:String(e),validate:r(n=>{if(!/^\d+$/.test(n))return"Must be an integer";const o=Number(n);if(o<20||o>200)return"Must be between 20 and 200"},"validate")});return D(t)},"askMaxLength"),Qe=r(async e=>{const t=await K({message:"Default commit type style",options:[{label:"None",value:"",hint:"Default"},{label:"Conventional",value:"conventional"}],initialValue:e});return M(t)?null:String(t)},"askType"),Xe=r(async e=>{const t=await P({message:"Sign-up message (optional)",initialValue:e,placeholder:"Signed-off-by: Sachin Thapa <contactsachin572@gmail.com>"});return D(t)},"askSignupMessage"),me=r(async()=>{const e=await E({},!0);console.log(`
|
|
163
|
+
Updated config:
|
|
164
|
+
`),console.log(Fe(e))},"printCurrentConfig"),Gt=r(async()=>{const e=await E({},!0);console.log(Ft(e))},"showCurrentConfig"),Ze=r(async()=>{G("lazycommit config setup");const e=await Ge();if(!e){v("Setup cancelled");return}const t=[["provider",e]];if(j(e)){const d=R(e),c=await ze(e);if(!c||!d){v("Setup cancelled");return}t.push([d,c])}const n=await We(e,Me(e));if(!n){v("Setup cancelled");return}const o=await Ye(1);if(!o){v("Setup cancelled");return}const s=await He("en");if(!s){v("Setup cancelled");return}const a=await Be("");if(a===null){v("Setup cancelled");return}const i=await Ve(1e3);if(!i){v("Setup cancelled");return}const u=await Je(100);if(!u){v("Setup cancelled");return}const l=await Qe("");if(l===null){v("Setup cancelled");return}const m=await Xe("");if(m===null){v("Setup cancelled");return}t.push(["model",n],["generate",o],["locale",s],["proxy",a],["timeout",i],["max-length",u],["type",l],["signup-message",m]),await ue(t),await me(),v("Configuration saved")},"runFirstTimeSetup"),zt=r(async()=>{G("lazycommit config change");let e=!0;for(;e;){const t=await E({},!0),n=t.provider,o=R(n),s=j(n),a=o?String(t[o]||""):"",i=[{label:`provider (${t.provider})`,value:"provider",hint:"Default: groq"},...s&&o?[{label:`${o} (required)`,value:"api-key",hint:`${ae(n)} API key`}]:[],{label:`model (${t.model})`,value:"model",hint:`Default: ${$e}`},{label:`generate (${t.generate})`,value:"generate",hint:"Default: 1"},{label:`locale (${t.locale})`,value:"locale",hint:"Default: en"},{label:`proxy (${t.proxy||"empty"})`,value:"proxy"},{label:`timeout (${t.timeout})`,value:"timeout",hint:"Default: 1000"},{label:`max-length (${t["max-length"]})`,value:"max-length",hint:"Default: 100"},{label:`type (${t.type||"empty"})`,value:"type",hint:"Default: empty"},{label:`signup-message (${t["signup-message"]||"empty"})`,value:"signup-message",hint:"Optional Signed-off-by trailer"},{label:"Done",value:"done"}],u=await K({message:"Select a setting to change",options:i});if(M(u)||u==="done"){e=!1;break}const l=String(u);let m=null;switch(l){case"provider":m=await Ge(n);break;case"api-key":m=await ze(n,a);break;case"model":m=await We(n,t.model);break;case"generate":m=await Ye(t.generate);break;case"locale":m=await He(t.locale);break;case"proxy":m=await Be(t.proxy);break;case"timeout":m=await Ve(t.timeout);break;case"max-length":m=await Je(t["max-length"]);break;case"type":m=await Qe(t.type);break;case"signup-message":m=await Xe(t["signup-message"]);break;default:throw new p(`Invalid option: ${l}`)}if(m===null)continue;if(l==="api-key"&&!o)throw new p(`Provider ${n} does not require an API key`);let d;if(l==="api-key"){if(!o)throw new p(`Provider ${n} does not require an API key`);d=o}else l==="provider"?d="provider":d=l;await ue([[d,m]]),console.log(`
|
|
165
|
+
Saved ${d}`);const c=await oe({message:"Change another setting?",initialValue:!0});(M(c)||!c)&&(e=!1)}await me(),v("Configuration updated")},"runChangeWizard");var Wt=fe({name:"config",parameters:["[mode]","[key=value...]"]},e=>{(async()=>{const{mode:t,keyValue:n}=e._,o=n||[];if(!t){await Ze();return}if(t==="get"){const s=await E({},!0);if(o.length===0){console.log(Fe(s));return}for(const a of o)if(Pe(s,a)){const i=s[a],u=i==null?"":String(i);console.log(`${a}=${u}`)}return}if(t==="set"){if(o.length===0)throw new p("Please provide one or more key=value pairs, for example: lazycommit config set locale=en");await ue(o.map(s=>s.split("="))),await me();return}if(t==="show"){await Gt();return}if(t==="change"){await zt();return}if(t==="setup"){await Ze();return}throw new p(`Invalid mode: ${t}`)})().catch(t=>{console.error(`${W("\u2716")} ${t.message}`),Y(t),process.exit(1)})});const et="prepare-commit-msg",tt=`.git/hooks/${et}`,X=pe(new URL("cli.mjs",import.meta.url)),Yt=process.argv[1].replace(/\\/g,"/").endsWith(`/${tt}`),nt=process.platform==="win32",ot=`
|
|
166
|
+
#!/usr/bin/env node
|
|
167
|
+
import(${JSON.stringify(ut(X))})
|
|
168
|
+
`.trim();var Ht=fe({name:"hook",parameters:["<install/uninstall>"]},e=>{(async()=>{const t=await De(),{installUninstall:n}=e._,o=te.join(t,tt),s=await be(o);if(n==="install"){if(s){if(await x.realpath(o).catch(()=>{})===X){console.warn("The hook is already installed");return}throw new p(`A different ${et} hook seems to be installed. Please remove it before installing lazycommit.`)}await x.mkdir(te.dirname(o),{recursive:!0}),nt?await x.writeFile(o,ot):(await x.symlink(X,o,"file"),await x.chmod(o,493)),console.log(`${z("\u2714")} Hook installed`);return}if(n==="uninstall"){if(!s){console.warn("Hook is not installed");return}if(nt){if(await x.readFile(o,"utf8")!==ot){console.warn("Hook is not installed");return}}else if(await x.realpath(o)!==X){console.warn("Hook is not installed");return}await x.rm(o),console.log(`${z("\u2714")} Hook uninstalled`);return}throw new p(`Invalid mode: ${n}`)})().catch(t=>{console.error(`${W("\u2716")} ${t.message}`),Y(t),process.exit(1)})});const Bt=pe(import.meta.url),Vt=ct(Bt),Jt=JSON.parse(rt(lt(Vt,"../package.json"),"utf8")),{description:Qt,version:Xt}=Jt,st=process.argv.slice(2);at({name:"lazycommit",version:Xt,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"},split:{type:Boolean,description:"Create multiple commits by grouping files logically",alias:"s",default:!1}},commands:[Wt,Ht],help:{description:Qt},ignoreArgv:r(e=>e==="unknown-flag"||e==="argument","ignoreArgv")},e=>{Yt?Ut():Lt(e.flags.generate,e.flags.exclude,e.flags.all,e.flags.type,e.flags.split,st)},st);
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sachinthapa572/lazycommit",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Writes your git commit messages for you with AI providers",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"git",
|
|
8
|
+
"commit",
|
|
9
|
+
"ai",
|
|
10
|
+
"groq",
|
|
11
|
+
"github",
|
|
12
|
+
"cli"
|
|
13
|
+
],
|
|
14
|
+
"author": "Sachin Thapa",
|
|
15
|
+
"license": "Apache-2.0",
|
|
16
|
+
"homepage": "https://lazycommit.vercel.app",
|
|
17
|
+
"repository": "sachin/lazycommit(fork)",
|
|
18
|
+
"type": "module",
|
|
19
|
+
"publishConfig": {
|
|
20
|
+
"access": "public"
|
|
21
|
+
},
|
|
22
|
+
"files": [
|
|
23
|
+
"dist"
|
|
24
|
+
],
|
|
25
|
+
"bin": {
|
|
26
|
+
"lazycommit": "./dist/cli.mjs",
|
|
27
|
+
"lzc": "./dist/cli.mjs"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@clack/prompts": "^0.11.0",
|
|
31
|
+
"@github/copilot-sdk": "^0.2.0",
|
|
32
|
+
"@types/ini": "^4.1.1",
|
|
33
|
+
"@types/inquirer": "^9.0.9",
|
|
34
|
+
"@types/node": "^24.5.1",
|
|
35
|
+
"@typescript/native-preview": "^7.0.0-dev.20260326.1",
|
|
36
|
+
"clean-pkg-json": "^1.3.0",
|
|
37
|
+
"cleye": "^1.3.4",
|
|
38
|
+
"execa": "^9.6.0",
|
|
39
|
+
"fs-fixture": "^2.8.1",
|
|
40
|
+
"groq-sdk": "^0.32.0",
|
|
41
|
+
"https-proxy-agent": "^7.0.6",
|
|
42
|
+
"ini": "^5.0.0",
|
|
43
|
+
"kolorist": "^1.8.0",
|
|
44
|
+
"manten": "^1.5.0",
|
|
45
|
+
"pkgroll": "^2.15.4",
|
|
46
|
+
"tsx": "^4.20.5",
|
|
47
|
+
"typescript": "^5.9.2"
|
|
48
|
+
}
|
|
49
|
+
}
|