Metadata-Version: 2.4
Name: gitai-cli
Version: 1.1.0
Summary: AI-powered git commit message generator
Project-URL: Homepage, https://github.com/Jeranguz/gitai
Project-URL: Repository, https://github.com/Jeranguz/gitai
Project-URL: Issues, https://github.com/Jeranguz/gitai/issues
Author: Jeranguz
License: MIT
License-File: LICENSE
Keywords: ai,cli,commit,conventional-commits,git,llm
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Version Control :: Git
Classifier: Topic :: Utilities
Requires-Python: >=3.11
Requires-Dist: gitpython
Requires-Dist: litellm
Requires-Dist: questionary
Requires-Dist: rich
Requires-Dist: tomli-w
Requires-Dist: typer
Provides-Extra: dev
Requires-Dist: pytest; extra == 'dev'
Description-Content-Type: text/markdown

# gitai

<p align="center">
  <img src="assets/commit-genie.png" alt="The Commit Genie" width="200"/>
</p>

<p align="center">
  <a href="https://pypi.org/project/gitai-cli"><img src="https://img.shields.io/pypi/v/gitai-cli" alt="PyPI version"/></a>
  <a href="https://pypi.org/project/gitai-cli"><img src="https://img.shields.io/pypi/pyversions/gitai-cli" alt="Python versions"/></a>
  <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="MIT license"/></a>
</p>

AI-powered git workflow tool. Generates meaningful commit messages and pull request descriptions from your diffs — using any LLM you already have access to.

## Features

- Reads your staged `git diff` and generates commit message suggestions (3 by default, configurable)
- Generates PR titles and descriptions from your branch's commits (`gitai pr`)
- Creates PRs and MRs directly via `gh` (GitHub) or `glab` (GitLab) with `--create`
- Interactive selection: pick a suggestion or write your own
- Supports multiple providers: Ollama (local), OpenAI, Anthropic, Gemini, and [more](https://docs.litellm.ai/docs/providers)
- Two commit styles: [Conventional Commits](https://www.conventionalcommits.org/) or free-form
- Optional emoji (gitmoji) support
- Automatically truncates large diffs to fit model context limits

## Installation

```bash
pip install gitai
```

Requires Python 3.11+.

## Quick start

```bash
# 1. Stage your changes
git add .

# 2. Run gitai
gitai commit
```

gitai reads the diff, calls your configured LLM, and presents 3 suggestions to choose from.

## Usage

```
gitai commit                   Generate commit message suggestions for staged changes
gitai commit --push            Push to remote automatically after committing
gitai commit -n 5              Generate 5 suggestions instead of the default 3
gitai commit --suggestions 5   Same as above

gitai pr                       Push branch and generate a PR title + description
gitai pr development           Compare against a specific base branch
gitai pr --full-diff           Use a flat diff instead of per-commit breakdown
gitai pr --minimal             Output title + bullet list only
gitai pr --template TEMPLATE   Fill in a custom PR template file
gitai pr --create              Create the PR/MR after generating (requires gh or glab)
gitai pr --create --draft      Create as a draft PR/MR

gitai config                   View and update settings
gitai --version                Show version
gitai --help                   Show help
```

## Configuration

Run `gitai config` to update settings interactively. Settings are stored in `~/.gitai.toml`.

| Key | Default | Description |
|---|---|---|
| `provider` | `ollama` | LLM provider |
| `model` | `llama3.2` | Model name |
| `ollama_url` | `http://localhost:11434` | Ollama API base URL (Ollama only) |
| `commit_style` | `conventional` | `conventional` or `free-form` |
| `emoji` | `false` | Prefix suggestions with gitmoji |
| `num_suggestions` | `3` | Number of suggestions to generate |
| `max_diff_chars` | `12000` | Max diff size sent to the model (truncates if exceeded) |

### Supported providers

| Provider | `provider` value | Example `model` value | API key env var |
|---|---|---|---|
| Ollama (local) | `ollama` | `llama3.2`, `mistral` | — |
| Anthropic | `anthropic` | `claude-sonnet-4-6`, `claude-haiku-4-5-20251001` | `ANTHROPIC_API_KEY` |
| OpenAI | `openai` | `gpt-4o`, `gpt-4o-mini` | `OPENAI_API_KEY` |
| Gemini | `gemini` | `gemini-2.0-flash` | `GEMINI_API_KEY` |

For cloud providers, set the API key in your shell profile:

**bash/zsh** (`~/.bashrc` or `~/.zshrc`):
```bash
export ANTHROPIC_API_KEY=sk-ant-...
```

**PowerShell** (`$PROFILE`):
```powershell
$env:ANTHROPIC_API_KEY="sk-ant-..."
```

### Example `~/.gitai.toml`

```toml
provider = "anthropic"
model = "claude-haiku-4-5-20251001"
commit_style = "conventional"
emoji = false
ollama_url = "http://localhost:11434"
```

## Generating PR descriptions

`gitai pr` pushes your current branch and generates a ready-to-copy PR title and description based on your commits.

```bash
# Auto-detect base branch (main/master/develop) and generate PR description
gitai pr

# Compare against a specific base branch
gitai pr development

# Use a flat diff instead of per-commit breakdown (good for large PRs)
gitai pr --full-diff

# Minimal output: title + bullet list only
gitai pr --minimal

# Fill in your team's PR template
gitai pr --template .github/PULL_REQUEST_TEMPLATE.md
```

If a `.github/PULL_REQUEST_TEMPLATE.md` exists in your repo, gitai will use it automatically.

### Creating PRs directly

Add `--create` to push the generated description straight to GitHub or GitLab:

```bash
# Create a PR on GitHub (requires gh: https://cli.github.com)
gitai pr --create

# Create a draft MR on GitLab (requires glab: https://gitlab.com/gitlab-org/cli)
gitai pr --create --draft
```

gitai detects your provider automatically from the remote URL (`github.com` or `gitlab.com`). You'll be prompted to confirm before anything is created. Make sure you're logged in with `gh auth login` or `glab auth login` first.

## Local setup (Ollama)

If you want to run fully offline with Ollama:

1. Install [Ollama](https://ollama.com/)
2. Pull a model: `ollama pull llama3.2`
3. Run `gitai commit` — no API key needed

## TODO

- [x] Allow configuring the number of suggestions generated
- [x] Add `gitai pr` command for PR description generation
- [x] Create PRs/MRs directly via `gh`/`glab` with `--create`
- [ ] Support unstaged changes with an optional `--all` flag
