Metadata-Version: 2.4
Name: prgen-cli
Version: 0.2.3
Summary: Generate PR titles and descriptions from git diff
Author: Jean Paul Fernandez
License-Expression: GPL-3.0-only
Project-URL: Homepage, https://github.com/jpxoi/prgen
Project-URL: Repository, https://github.com/jpxoi/prgen
Project-URL: Issues, https://github.com/jpxoi/prgen/issues
Keywords: cli,git,pull-request,diff,llm,openai,gemini
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Version Control
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: google-genai>=1.70.0
Requires-Dist: openai>=2.30.0
Requires-Dist: rich>=14.3.3
Requires-Dist: typer>=0.24.1
Dynamic: license-file

# prgen

Generate a pull request title and description from `git diff` and commit history.

**Author:** Jean Paul Fernandez · [github.com/jpxoi/prgen](https://github.com/jpxoi/prgen)

Licensed under the [GNU General Public License v3.0](LICENSE) (GPL-3.0-only): you may share and modify this program under those terms; see the license file for full conditions.

## Requirements

- **Python** 3.10+
- **`git`** on your `PATH` (install Git and ensure `git` works in a terminal)

## Install

From PyPI, install the **`prgen-cli`** package; the **`prgen`** command is what you run in the terminal.

From [PyPI](https://pypi.org/project/prgen-cli/):

```bash
pip install prgen-cli
# or
uv tool install prgen-cli
```

From a clone (installs all dependencies):

```bash
uv sync
```

Formatting / lint (see `[tool.ruff]` in `pyproject.toml`):

```bash
uv run ruff format .
uv run ruff check .
```

## Setup

Store settings in **`~/.config/prgen/config.json`** using **`prgen config`** (interactive prompts, or `prgen config set …`). Supported fields:

- `OPENAI_API_KEY` — OpenAI API key (also merged into the environment when you run `prgen`, if not already set)
- `GOOGLE_API_KEY` — Google AI Studio / Gemini API key (same behavior)
- `base` — optional default for **`--base`** (see [Defaults](#defaults) below)
- `provider` — optional default for **`--provider`**
- `tier` — optional default for **`--tier`**

Override the config directory with **`XDG_CONFIG_HOME`** (file is `$XDG_CONFIG_HOME/prgen/config.json`).

## Defaults

Defaults apply to the **main** `prgen` command (generating a PR summary), not to `prgen config …` subcommands.

### Built-in CLI defaults (no config file)

If you do not pass a flag and the key is **not** set in `config.json`, prgen uses:

| What | Default | Meaning |
| ---: | ---: | ---: |
| Git repo | current directory | Diff and log are for the repo you run from. Use **`-C` / `--repo`** for another tree. |
| **`--base`** | `origin/main` | Compare `HEAD` to this ref (`git diff` / `git log` vs merge base). The ref must exist locally (e.g. run **`git fetch origin`** or use a local branch like `main`). |
| **`--provider`** | `auto` | Pick a backend from your API keys: **Gemini** if `GOOGLE_API_KEY` is set, otherwise **OpenAI** if `OPENAI_API_KEY` is set. If neither is set, prgen exits with an error until you configure keys. |
| **`--tier`** | `default` | Cheaper/faster model preset. **`pro`** selects a stronger model for the chosen provider. |
| **`--model`** | *(unset)* | Use the model for the current **`--tier`** (see presets in the source under `defaults.py`). **`--model ID`** overrides **`--tier`** entirely. |
| **`--context`** | `none` | Extra text merged into the prompt; the literal string **`none`** means “no extra context” unless you change it. |

### Optional overrides from `config.json`

If **`base`**, **`provider`**, or **`tier`** appear in `config.json`, they **replace** the built-in defaults **only when you do not pass the matching flag**.

- Example: `base` in JSON is `main`, and you run **`prgen`** with no **`--base`** → effective base is **`main`**.
- Example: same config, but you run **`prgen --base origin/main`** → **`--base`** wins; the file is ignored for that run.

**`--model`** and **`--context`** are not read from the JSON file; only **`base`**, **`provider`**, and **`tier`** are.

### Summary

- **Config file** fills in **`--base`**, **`--provider`**, and **`--tier`** when those flags are omitted.
- **Explicit flags** always override the file.
- **`auto`** chooses Gemini vs OpenAI from which API keys are available (see **`--provider`** above).

### Set keys from the CLI

Writes go to **`~/.config/prgen/config.json`** (see `prgen config path`). Allowed keys: **`OPENAI_API_KEY`**, **`GOOGLE_API_KEY`**, **`base`**, **`provider`**, **`tier`**.

```bash
prgen config                    # wizard: API keys + base, provider, tier (Rich prompts)
prgen config set OPENAI_API_KEY sk-...
prgen config set GOOGLE_API_KEY - < key.txt    # value read from stdin
prgen config unset OPENAI_API_KEY
prgen config show                              # safe summary (keys as set/unset; colors if TTY)
prgen config path                              # print path to the file
```

## Run on another project

Use **`-C`** (same idea as `git -C`) so you can run `prgen` from anywhere:

```bash
prgen -C ~/src/my-application
```

If `prgen` is not on your `PATH`, invoke it via `uv` from the prgen repo:

```bash
uv run --directory /path/to/prgen prgen -C ~/src/my-application
```

## Install globally (optional)

From the prgen project directory:

```bash
uv tool install .
# or
pipx install .
```

Then `prgen` is available in new shells (ensure your tool install `bin` directory is on `PATH`).

## Options

See **`prgen --help`** for all flags. In addition to [Defaults](#defaults):

- If there is **no diff and no commits** compared to **`--base`**, prgen exits with an error (nothing to summarize).
