ikomet 0.1.1__tar.gz

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.
ikomet-0.1.1/PKG-INFO ADDED
@@ -0,0 +1,250 @@
1
+ Metadata-Version: 2.4
2
+ Name: ikomet
3
+ Version: 0.1.1
4
+ Summary: AI-powered Conventional Commit message generator using your staged changes
5
+ Author: ajabri
6
+ Author-email: abdelalijabri76@gmail.com
7
+ Requires-Python: >=3.10,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.10
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Programming Language :: Python :: 3.14
14
+ Requires-Dist: gitpython (>=3.1.43,<4.0.0)
15
+ Requires-Dist: groq (>=1.0.0,<2.0.0)
16
+ Requires-Dist: typer[all] (>=0.12.0,<0.13.0)
17
+ Project-URL: Homepage, https://github.com/ajabrii/Komet
18
+ Project-URL: Repository, https://github.com/ajabrii/Komet
19
+ Description-Content-Type: text/markdown
20
+
21
+ # πŸš€ Komet
22
+
23
+ **AI-Powered Conventional Commit Message Generator**
24
+
25
+ Komet is a smart CLI tool that leverages Groq's LLM API to automatically generate professional, [Conventional Commits](https://www.conventionalcommits.org/) formatted commit messages from your staged git changes. Say goodbye to bland commit messages and hello to consistent, meaningful version control history.
26
+
27
+ [![Python](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
28
+ [![Poetry](https://img.shields.io/badge/poetry-dependency%20management-blueviolet)](https://python-poetry.org/)
29
+ [![Groq](https://img.shields.io/badge/powered%20by-Groq%20LLM-orange)](https://groq.com/)
30
+
31
+ ---
32
+
33
+ ## ✨ Features
34
+
35
+ - **πŸ€– AI-Powered Analysis**: Uses Groq's fast LLM (Llama 3.3 70B) to understand your code changes
36
+ - **πŸ“ Conventional Commits**: Automatically follows industry-standard commit message format
37
+ - **⚑ Lightning Fast**: Groq's infrastructure provides near-instant responses
38
+ - **🎯 Context-Aware**: Analyzes actual git diffs to generate accurate, meaningful messages
39
+ - **πŸ›‘οΈ Safe & Smart**: Truncates large diffs, validates git repos, and handles edge cases gracefully
40
+ - **🎨 Beautiful CLI**: Built with Typer for a modern, user-friendly command-line experience
41
+
42
+ ---
43
+
44
+ ## 🎬 Demo
45
+
46
+ ```bash
47
+ # Stage your changes
48
+ $ git add src/komet/main.py
49
+
50
+ # Let Komet generate the commit message
51
+ $ komet
52
+
53
+ Suggested commit message:
54
+
55
+ feat(main): add automatic diff truncation for large changesets
56
+
57
+ Use it like this:
58
+ git commit -m 'feat(main): add automatic diff truncation for large changesets'
59
+ ```
60
+
61
+ ---
62
+
63
+ ## πŸš€ Installation
64
+
65
+ ### Prerequisites
66
+
67
+ - Python 3.10 or higher
68
+ - Poetry (Python dependency management)
69
+ - Git repository
70
+ - Groq API key ([Get it here](https://console.groq.com/keys))
71
+
72
+ ### Install via Poetry
73
+
74
+ ```bash
75
+ # Clone the repository
76
+ git clone https://github.com/ajabrii/Komet.git
77
+ cd Komet
78
+
79
+ # Install dependencies
80
+ poetry install
81
+
82
+ # Set your Groq API key
83
+ export GROQ_API_KEY=gq_xxxxxxxxxxxxxxxx
84
+
85
+ # Run Komet
86
+ poetry run komet
87
+ ```
88
+
89
+ ### Install as Global Command
90
+
91
+ ```bash
92
+ # Install with pipx (recommended)
93
+ pipx install .
94
+
95
+ # Or install globally with poetry
96
+ poetry build
97
+ pip install dist/komet-0.1.0-py3-none-any.whl
98
+
99
+ # Now use it anywhere
100
+ komet
101
+ ```
102
+
103
+ ---
104
+
105
+ ## πŸ“– Usage
106
+
107
+ ### Basic Workflow
108
+
109
+ 1. **Stage your changes** as usual:
110
+ ```bash
111
+ git add <files>
112
+ ```
113
+
114
+ 2. **Run Komet**:
115
+ ```bash
116
+ komet
117
+ ```
118
+
119
+ 3. **Copy and commit** with the suggested message:
120
+ ```bash
121
+ git commit -m '<generated-message>'
122
+ ```
123
+
124
+ ### Environment Setup
125
+
126
+ Komet requires a Groq API key. Set it up once:
127
+
128
+ ```bash
129
+ # Temporary (current session only)
130
+ export GROQ_API_KEY=gq_xxxxxxxxxxxxxxxx
131
+
132
+ # Permanent (add to ~/.bashrc, ~/.zshrc, or ~/.profile)
133
+ echo 'export GROQ_API_KEY=gq_xxxxxxxxxxxxxxxx' >> ~/.bashrc
134
+ source ~/.bashrc
135
+ ```
136
+
137
+ ---
138
+
139
+ ## πŸ—οΈ How It Works
140
+
141
+ 1. **Git Diff Extraction**: Komet uses GitPython to read your staged changes (`git diff --cached`)
142
+ 2. **Context Preparation**: The diff is sent to Groq's LLM with a carefully crafted system prompt
143
+ 3. **AI Analysis**: The LLM analyzes the code changes and generates a Conventional Commit message
144
+ 4. **Formatted Output**: The result is displayed with usage instructions
145
+
146
+ ### Conventional Commit Format
147
+
148
+ Komet generates messages following this structure:
149
+
150
+ ```
151
+ <type>(<optional-scope>): <short-description>
152
+
153
+ <optional-body>
154
+
155
+ <optional-footer>
156
+ ```
157
+
158
+ **Supported types**: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert`
159
+
160
+ ---
161
+
162
+ ## πŸ› οΈ Technology Stack
163
+
164
+ | Technology | Purpose |
165
+ |------------|---------|
166
+ | **Python 3.10+** | Core programming language |
167
+ | **Poetry** | Dependency management and packaging |
168
+ | **Typer** | Modern CLI framework with beautiful output |
169
+ | **GitPython** | Git repository interaction |
170
+ | **Groq SDK** | LLM API integration (Llama 3.3 70B) |
171
+
172
+ ---
173
+
174
+ ## πŸ“ Project Structure
175
+
176
+ ```
177
+ Komet/
178
+ β”œβ”€β”€ src/
179
+ β”‚ └── komet/
180
+ β”‚ β”œβ”€β”€ __init__.py # Package initialization
181
+ β”‚ └── main.py # Core application logic
182
+ β”œβ”€β”€ pyproject.toml # Poetry configuration & dependencies
183
+ └── README.md # Project documentation
184
+ ```
185
+
186
+ ---
187
+
188
+ ## πŸ”§ Configuration
189
+
190
+ ### Model Selection
191
+
192
+ Komet uses `llama-3.3-70b-versatile` by default. You can modify [main.py](src/komet/main.py#L79) to use other Groq models:
193
+
194
+ - `llama-3.3-70b-versatile` - Best quality & speed balance (default)
195
+ - `mixtral-8x7b-32768` - Cheaper alternative, still excellent quality
196
+
197
+ ### Diff Size Limits
198
+
199
+ Large diffs are automatically truncated to 15,000 characters to fit within LLM context windows. Adjust in [main.py](src/komet/main.py#L42).
200
+
201
+ ---
202
+
203
+ ## 🀝 Contributing
204
+
205
+ Contributions are welcome! Here's how you can help:
206
+
207
+ 1. Fork the repository
208
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
209
+ 3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
210
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
211
+ 5. Open a Pull Request
212
+
213
+ ---
214
+
215
+ ## πŸ“ License
216
+
217
+ This project is open source and available under the [MIT License](LICENSE).
218
+
219
+ ---
220
+
221
+ ## πŸ‘€ Author
222
+
223
+ **Abdelali Jabri**
224
+ - LinkedIn: [Linkedin](https://www.linkedin.com/in/abdelali-jabri-51729b2b0/)
225
+ - GitHub: [@ajabrii](https://github.com/ajabrii)
226
+ - Email: abdelalijabri76@gmail.com
227
+
228
+ ---
229
+
230
+ ## πŸ™ Acknowledgments
231
+
232
+ - [Conventional Commits](https://www.conventionalcommits.org/) - For the commit message specification
233
+ - [Groq](https://groq.com/) - For providing lightning-fast LLM inference
234
+ - [Typer](https://typer.tiangolo.com/) - For the excellent CLI framework
235
+
236
+ ---
237
+
238
+ ## 🌟 Why Komet?
239
+
240
+ In professional software development, clear commit history is crucial for:
241
+ - **Code Reviews**: Understanding what changed and why
242
+ - **Debugging**: Using `git bisect` to find when bugs were introduced
243
+ - **Documentation**: Auto-generating changelogs from commits
244
+ - **Team Collaboration**: Maintaining consistency across team members
245
+
246
+ Komet automates best practices, ensuring every commit tells a clear story.
247
+
248
+ ---
249
+
250
+ **Made with ❀️ by Abdelali Jabri**
ikomet-0.1.1/README.md ADDED
@@ -0,0 +1,230 @@
1
+ # πŸš€ Komet
2
+
3
+ **AI-Powered Conventional Commit Message Generator**
4
+
5
+ Komet is a smart CLI tool that leverages Groq's LLM API to automatically generate professional, [Conventional Commits](https://www.conventionalcommits.org/) formatted commit messages from your staged git changes. Say goodbye to bland commit messages and hello to consistent, meaningful version control history.
6
+
7
+ [![Python](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
8
+ [![Poetry](https://img.shields.io/badge/poetry-dependency%20management-blueviolet)](https://python-poetry.org/)
9
+ [![Groq](https://img.shields.io/badge/powered%20by-Groq%20LLM-orange)](https://groq.com/)
10
+
11
+ ---
12
+
13
+ ## ✨ Features
14
+
15
+ - **πŸ€– AI-Powered Analysis**: Uses Groq's fast LLM (Llama 3.3 70B) to understand your code changes
16
+ - **πŸ“ Conventional Commits**: Automatically follows industry-standard commit message format
17
+ - **⚑ Lightning Fast**: Groq's infrastructure provides near-instant responses
18
+ - **🎯 Context-Aware**: Analyzes actual git diffs to generate accurate, meaningful messages
19
+ - **πŸ›‘οΈ Safe & Smart**: Truncates large diffs, validates git repos, and handles edge cases gracefully
20
+ - **🎨 Beautiful CLI**: Built with Typer for a modern, user-friendly command-line experience
21
+
22
+ ---
23
+
24
+ ## 🎬 Demo
25
+
26
+ ```bash
27
+ # Stage your changes
28
+ $ git add src/komet/main.py
29
+
30
+ # Let Komet generate the commit message
31
+ $ komet
32
+
33
+ Suggested commit message:
34
+
35
+ feat(main): add automatic diff truncation for large changesets
36
+
37
+ Use it like this:
38
+ git commit -m 'feat(main): add automatic diff truncation for large changesets'
39
+ ```
40
+
41
+ ---
42
+
43
+ ## πŸš€ Installation
44
+
45
+ ### Prerequisites
46
+
47
+ - Python 3.10 or higher
48
+ - Poetry (Python dependency management)
49
+ - Git repository
50
+ - Groq API key ([Get it here](https://console.groq.com/keys))
51
+
52
+ ### Install via Poetry
53
+
54
+ ```bash
55
+ # Clone the repository
56
+ git clone https://github.com/ajabrii/Komet.git
57
+ cd Komet
58
+
59
+ # Install dependencies
60
+ poetry install
61
+
62
+ # Set your Groq API key
63
+ export GROQ_API_KEY=gq_xxxxxxxxxxxxxxxx
64
+
65
+ # Run Komet
66
+ poetry run komet
67
+ ```
68
+
69
+ ### Install as Global Command
70
+
71
+ ```bash
72
+ # Install with pipx (recommended)
73
+ pipx install .
74
+
75
+ # Or install globally with poetry
76
+ poetry build
77
+ pip install dist/komet-0.1.0-py3-none-any.whl
78
+
79
+ # Now use it anywhere
80
+ komet
81
+ ```
82
+
83
+ ---
84
+
85
+ ## πŸ“– Usage
86
+
87
+ ### Basic Workflow
88
+
89
+ 1. **Stage your changes** as usual:
90
+ ```bash
91
+ git add <files>
92
+ ```
93
+
94
+ 2. **Run Komet**:
95
+ ```bash
96
+ komet
97
+ ```
98
+
99
+ 3. **Copy and commit** with the suggested message:
100
+ ```bash
101
+ git commit -m '<generated-message>'
102
+ ```
103
+
104
+ ### Environment Setup
105
+
106
+ Komet requires a Groq API key. Set it up once:
107
+
108
+ ```bash
109
+ # Temporary (current session only)
110
+ export GROQ_API_KEY=gq_xxxxxxxxxxxxxxxx
111
+
112
+ # Permanent (add to ~/.bashrc, ~/.zshrc, or ~/.profile)
113
+ echo 'export GROQ_API_KEY=gq_xxxxxxxxxxxxxxxx' >> ~/.bashrc
114
+ source ~/.bashrc
115
+ ```
116
+
117
+ ---
118
+
119
+ ## πŸ—οΈ How It Works
120
+
121
+ 1. **Git Diff Extraction**: Komet uses GitPython to read your staged changes (`git diff --cached`)
122
+ 2. **Context Preparation**: The diff is sent to Groq's LLM with a carefully crafted system prompt
123
+ 3. **AI Analysis**: The LLM analyzes the code changes and generates a Conventional Commit message
124
+ 4. **Formatted Output**: The result is displayed with usage instructions
125
+
126
+ ### Conventional Commit Format
127
+
128
+ Komet generates messages following this structure:
129
+
130
+ ```
131
+ <type>(<optional-scope>): <short-description>
132
+
133
+ <optional-body>
134
+
135
+ <optional-footer>
136
+ ```
137
+
138
+ **Supported types**: `feat`, `fix`, `docs`, `style`, `refactor`, `perf`, `test`, `build`, `ci`, `chore`, `revert`
139
+
140
+ ---
141
+
142
+ ## πŸ› οΈ Technology Stack
143
+
144
+ | Technology | Purpose |
145
+ |------------|---------|
146
+ | **Python 3.10+** | Core programming language |
147
+ | **Poetry** | Dependency management and packaging |
148
+ | **Typer** | Modern CLI framework with beautiful output |
149
+ | **GitPython** | Git repository interaction |
150
+ | **Groq SDK** | LLM API integration (Llama 3.3 70B) |
151
+
152
+ ---
153
+
154
+ ## πŸ“ Project Structure
155
+
156
+ ```
157
+ Komet/
158
+ β”œβ”€β”€ src/
159
+ β”‚ └── komet/
160
+ β”‚ β”œβ”€β”€ __init__.py # Package initialization
161
+ β”‚ └── main.py # Core application logic
162
+ β”œβ”€β”€ pyproject.toml # Poetry configuration & dependencies
163
+ └── README.md # Project documentation
164
+ ```
165
+
166
+ ---
167
+
168
+ ## πŸ”§ Configuration
169
+
170
+ ### Model Selection
171
+
172
+ Komet uses `llama-3.3-70b-versatile` by default. You can modify [main.py](src/komet/main.py#L79) to use other Groq models:
173
+
174
+ - `llama-3.3-70b-versatile` - Best quality & speed balance (default)
175
+ - `mixtral-8x7b-32768` - Cheaper alternative, still excellent quality
176
+
177
+ ### Diff Size Limits
178
+
179
+ Large diffs are automatically truncated to 15,000 characters to fit within LLM context windows. Adjust in [main.py](src/komet/main.py#L42).
180
+
181
+ ---
182
+
183
+ ## 🀝 Contributing
184
+
185
+ Contributions are welcome! Here's how you can help:
186
+
187
+ 1. Fork the repository
188
+ 2. Create a feature branch (`git checkout -b feature/amazing-feature`)
189
+ 3. Commit your changes (`git commit -m 'feat: add amazing feature'`)
190
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
191
+ 5. Open a Pull Request
192
+
193
+ ---
194
+
195
+ ## πŸ“ License
196
+
197
+ This project is open source and available under the [MIT License](LICENSE).
198
+
199
+ ---
200
+
201
+ ## πŸ‘€ Author
202
+
203
+ **Abdelali Jabri**
204
+ - LinkedIn: [Linkedin](https://www.linkedin.com/in/abdelali-jabri-51729b2b0/)
205
+ - GitHub: [@ajabrii](https://github.com/ajabrii)
206
+ - Email: abdelalijabri76@gmail.com
207
+
208
+ ---
209
+
210
+ ## πŸ™ Acknowledgments
211
+
212
+ - [Conventional Commits](https://www.conventionalcommits.org/) - For the commit message specification
213
+ - [Groq](https://groq.com/) - For providing lightning-fast LLM inference
214
+ - [Typer](https://typer.tiangolo.com/) - For the excellent CLI framework
215
+
216
+ ---
217
+
218
+ ## 🌟 Why Komet?
219
+
220
+ In professional software development, clear commit history is crucial for:
221
+ - **Code Reviews**: Understanding what changed and why
222
+ - **Debugging**: Using `git bisect` to find when bugs were introduced
223
+ - **Documentation**: Auto-generating changelogs from commits
224
+ - **Team Collaboration**: Maintaining consistency across team members
225
+
226
+ Komet automates best practices, ensuring every commit tells a clear story.
227
+
228
+ ---
229
+
230
+ **Made with ❀️ by Abdelali Jabri**
@@ -0,0 +1,22 @@
1
+ [tool.poetry]
2
+ name = "ikomet"
3
+ version = "0.1.1"
4
+ description = "AI-powered Conventional Commit message generator using your staged changes"
5
+ authors = ["ajabri <abdelalijabri76@gmail.com>"]
6
+ readme = "README.md"
7
+ packages = [{include = "komet", from = "src"}]
8
+ homepage = "https://github.com/ajabrii/Komet"
9
+ repository = "https://github.com/ajabrii/Komet"
10
+
11
+ [tool.poetry.dependencies]
12
+ python = "^3.10"
13
+ typer = {extras = ["all"], version = "^0.12.0"}
14
+ gitpython = "^3.1.43"
15
+ groq = "^1.0.0"
16
+
17
+ [tool.poetry.scripts]
18
+ komet = "komet.main:app"
19
+
20
+ [build-system]
21
+ requires = ["poetry-core>=1.0.0"]
22
+ build-backend = "poetry.core.masonry.api"
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
@@ -0,0 +1,161 @@
1
+ # src/komet/main.py
2
+
3
+ import os
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ import git # GitPython library to interact with git
8
+ from groq import Groq # Official Groq SDK for calling their API
9
+ import typer # Modern, beautiful CLI framework (like Click but nicer)
10
+
11
+ # Create the main Typer application
12
+ # name="komet" β†’ the command will be called "komet"
13
+ # help=... β†’ shown when user runs: komet --help
14
+ app = typer.Typer(
15
+ name="komet",
16
+ help="Generate a Conventional Commit message from staged changes using Groq LLM",
17
+ add_completion=False, # disables shell completion (we don't need it yet)
18
+ )
19
+
20
+
21
+ def get_staged_diff() -> str:
22
+ """
23
+ Read the staged changes (what `git diff --cached` would show).
24
+ Returns the diff as string or exits with error message.
25
+ """
26
+ # Try to open the current directory (or parent) as git repo
27
+ try:
28
+ repo = git.Repo(Path.cwd(), search_parent_directories=True)
29
+ except git.InvalidGitRepositoryError:
30
+ typer.secho("Error: Not inside a git repository.", fg=typer.colors.RED, err=True)
31
+ raise typer.Exit(code=1)
32
+
33
+ # Check if there are actually staged changes
34
+ if not repo.is_dirty(index=True): # index=True β†’ checks staged area
35
+ typer.secho("No staged changes found.", fg=typer.colors.YELLOW, err=True)
36
+ raise typer.Exit(code=0)
37
+
38
+ # Get the actual diff of staged files
39
+ diff = repo.git.diff("--cached") # same as: git diff --cached
40
+
41
+ # Safety: if somehow diff is empty
42
+ if not diff.strip():
43
+ typer.secho("Staged changes are empty.", fg=typer.colors.YELLOW, err=True)
44
+ raise typer.Exit(code=0)
45
+
46
+ # Optional: prevent sending huge diffs (Groq has large context, but still good practice)
47
+ MAX_DIFF_CHARS = 15000
48
+ if len(diff) > MAX_DIFF_CHARS:
49
+ diff = diff[:MAX_DIFF_CHARS] + "\n\n# ... (diff was truncated to fit context)"
50
+
51
+ return diff
52
+
53
+
54
+ def generate_commit_message(diff_text: str, api_key: str) -> str:
55
+ """
56
+ Send the diff to Groq LLM and ask it to create a Conventional Commit message.
57
+ Returns only the generated message string.
58
+ """
59
+ client = Groq(api_key=api_key)
60
+
61
+ # This is the most important part β€” controls quality a lot
62
+ system_prompt = """You are a senior software engineer who writes **perfect, team-friendly Conventional Commits** every time.
63
+
64
+ MANDATORY RULES β€” follow exactly or the output is invalid:
65
+
66
+ 1. Type must be one of: feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
67
+ 2. Add scope in (parentheses) when it adds clarity (db, api, auth, ui, cli, config, tests, …)
68
+ 3. Subject line: imperative mood ("add feature", "fix bug", "refactor class") β€” NEVER past tense
69
+ 4. Subject line length: maximum 72 characters (including type and scope)
70
+ 5. No period at the end of the subject line
71
+ 6. If the change affects public API / breaks compatibility β†’ add footer: BREAKING CHANGE: one sentence explanation
72
+ 7. Optional body: after one blank line β€” explain WHAT changed and WHY (keep under 4 lines)
73
+ 8. Use bullet points in body only if it really helps readability
74
+ 9. Never include:
75
+ - Emojis
76
+ - Markdown formatting
77
+ - ``` fences
78
+ - Explanations outside the message
79
+ - "Here is the commit message:"
80
+ 10. Output **ONLY** the final commit message β€” nothing else
81
+
82
+ Few perfect examples:
83
+
84
+ feat: add password reset flow
85
+ fix: correct JWT token validation on refresh
86
+
87
+ docs(readme): update installation instructions with poetry commands
88
+
89
+ refactor(cli): extract diff parsing to separate function
90
+ - Improves testability
91
+ - Reduces main.py complexity
92
+
93
+ BREAKING CHANGE: removed deprecated --old-flag option
94
+
95
+ Your turn β€” analyze the diff and create the message.
96
+ """
97
+
98
+ user_prompt = f"""Analyze these staged code changes and write the commit message:
99
+
100
+ {diff_text}
101
+ """
102
+
103
+ try:
104
+ response = client.chat.completions.create(
105
+ model="llama-3.3-70b-versatile", # good balance of quality & speed on Groq
106
+ # model="mixtral-8x7b-32768", # cheaper & still very good
107
+ messages=[
108
+ {"role": "system", "content": system_prompt},
109
+ {"role": "user", "content": user_prompt},
110
+ ],
111
+ temperature=0.15, # low = more consistent & deterministic
112
+ max_tokens=180, # enough for message + body
113
+ top_p=0.9,
114
+ )
115
+
116
+ message = response.choices[0].message.content.strip()
117
+ return message
118
+
119
+ except Exception as e:
120
+ typer.secho(f"Groq API error: {str(e)}", fg=typer.colors.RED, err=True)
121
+ raise typer.Exit(code=1)
122
+
123
+
124
+ @app.command()
125
+ def main():
126
+ """
127
+ Main command β€” called when user just types: komet
128
+ """
129
+ # Get Groq API key from environment (most secure & common way)
130
+ api_key = os.getenv("GROQ_API_KEY")
131
+ if not api_key:
132
+ typer.secho(
133
+ "Error: GROQ_API_KEY environment variable is not set.\n"
134
+ "Get your key at: https://console.groq.com/keys\n"
135
+ "Then run: export GROQ_API_KEY=gq_xxxxxxxxxxxxxxxx",
136
+ fg=typer.colors.RED,
137
+ err=True
138
+ )
139
+ raise typer.Exit(code=1)
140
+
141
+ # 1. Read staged changes
142
+ diff = get_staged_diff()
143
+
144
+ # 2. Ask LLM to generate message
145
+ message = generate_commit_message(diff, api_key)
146
+
147
+ # 3. Print nicely
148
+ typer.echo("\nSuggested commit message:\n")
149
+ typer.secho(message, fg=typer.colors.GREEN, bold=True)
150
+ typer.echo("\nUse it like this:")
151
+ typer.echo(f" git commit -m '{message.splitlines()[0]}'")
152
+ # If message has body β†’ show full multi-line version
153
+ if "\n" in message:
154
+ typer.echo("\nFull version:")
155
+ typer.echo(message)
156
+
157
+
158
+ if __name__ == "__main__":
159
+ # This makes the script runnable directly: python -m komet
160
+ # But normally you'll run it via poetry run komet or after pipx install
161
+ app()