Metadata-Version: 2.4
Name: gai-commit
Version: 0.1.2
Summary: An AI-powered git commit message generator.
Author-email: Muzahid <mmsaddam@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Muzahid
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Project-URL: Homepage, https://github.com/muzahid59/gai
Project-URL: Bug Tracker, https://github.com/muzahid59/gai/issues
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development :: Version Control :: Git
Classifier: Topic :: Utilities
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests
Requires-Dist: python-dotenv
Requires-Dist: openai
Dynamic: license-file

# gai-commit

AI-powered CLI tool to generate commit messages from your staged Git changes. Works with both local Ollama models and OpenAI's API.

## Installation

```bash
pip install gai-commit
```

## Usage Options

### 1. Using Ollama (Local LLMs)

Ollama provides free, locally-running AI models with no API keys required.

**Prerequisites:**
```bash
# 1. Install Ollama (https://ollama.com)
# 2. Pull a model (only needed once):
ollama pull llama3.2
# Ollama daemon should start automatically after installation
```

**Basic Usage:**
```bash
# Stage your changes first
git add path/to/modified/files

# Generate commit message with default model
gai

# Or specify a different Ollama model
gai deepseek-r1:8b
```

### 2. Using OpenAI (Cloud-based LLMs)

For higher quality results, you can use OpenAI's models (requires API key).

**Prerequisites:**
```bash
# Set your OpenAI API key (or add to .env file)
export OPENAI_API_KEY=sk-your-key
```

**Basic Usage:**
```bash
# Stage your changes first
git add path/to/modified/files

# Generate commit message with default model (gpt-3.5-turbo)
gai --provider openai

# Or specify a different OpenAI model
gai --provider openai gpt-4o
```

### Additional Options

```bash
# Generate a concise one-line commit message (subject only)
gai --oneline

# Combine with provider selection
gai --provider openai --oneline
```

## How It Works

1. **Repository Check**: Verifies you're in a git repository via [`gai.utils.is_git_repository`](src/gai/utils.py)
2. **Diff Collection**: Gets staged changes with `git diff --staged --minimal --unified=5` using [`gai.utils.get_staged_diff`](src/gai/utils.py)
3. **AI Processing**: Sends the cleaned diff to the selected AI provider through [`gai.cli.generate_commit_message`](src/gai/cli.py)
4. **Output Cleaning**: Formats the AI output and removes technical artifacts via [`gai.utils.clean_commit_message`](src/gai/utils.py)
5. **Interactive Workflow**: Presents options to apply, edit, regenerate or quit via [`gai.cli.handle_user_choice`](src/gai/cli.py)
6. **Commit**: Applies your approved message with `git commit`

## Interactive Workflow

After generating a commit message suggestion, you'll see:

```
Suggested Commit Message:
feat(parser): improve error resilience

- add fallback recovery for malformed input
- reduce panic cases in edge parsing paths
---
[A]pply, [E]dit, [R]-generate, or [Q]uit? (a/e/r/q)
```

Your options:
- **A**: Apply immediately (`git commit -m "<message>"`)
- **E**: Open your `$EDITOR` (defaults to `vim`) to refine the message
- **R**: Ask the AI to generate a new suggestion using the same diff
- **Q**: Quit without committing

## Troubleshooting

### Common Issues

- **"No staged changes found"**: Use `git add` to stage your changes first
- **"Not a Git repository"**: Make sure you're inside a valid git repository
- **"OPENAI_API_KEY environment variable not set"**: Set your OpenAI API key or use Ollama
- **"Ollama connection refused"**: Make sure the Ollama daemon is running (`ollama serve`)

## Development

```bash
# Clone the repository
git clone https://github.com/muzahid59/gai
cd gai

# Install in development mode
pip install -e .

# Run tests
pytest tests -v
```

## Benchmarking

Compare different models' performance:

```bash
# Make sure to stage some changes first
python run_benchmark.py
```

## License

MIT - see [LICENSE](LICENSE)
