prgen-cli 0.4.0__tar.gz → 0.5.0__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.
Files changed (33) hide show
  1. prgen_cli-0.5.0/PKG-INFO +441 -0
  2. prgen_cli-0.5.0/README.md +415 -0
  3. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/pyproject.toml +3 -3
  4. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen/api_errors.py +6 -6
  5. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen/cli.py +395 -71
  6. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen/config.py +77 -23
  7. prgen_cli-0.5.0/src/prgen/defaults.py +68 -0
  8. prgen_cli-0.5.0/src/prgen/gh_utils.py +213 -0
  9. prgen_cli-0.5.0/src/prgen/git_utils.py +187 -0
  10. prgen_cli-0.5.0/src/prgen/prompting.py +136 -0
  11. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen/prompts/pr_description.txt +6 -5
  12. prgen_cli-0.5.0/src/prgen/providers/cli_agent_provider.py +204 -0
  13. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen/providers/gemini_provider.py +10 -2
  14. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen/providers/openai_provider.py +7 -2
  15. prgen_cli-0.5.0/src/prgen_cli.egg-info/PKG-INFO +441 -0
  16. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen_cli.egg-info/SOURCES.txt +2 -0
  17. prgen_cli-0.4.0/PKG-INFO +0 -299
  18. prgen_cli-0.4.0/README.md +0 -273
  19. prgen_cli-0.4.0/src/prgen/defaults.py +0 -24
  20. prgen_cli-0.4.0/src/prgen/git_utils.py +0 -74
  21. prgen_cli-0.4.0/src/prgen/prompting.py +0 -25
  22. prgen_cli-0.4.0/src/prgen_cli.egg-info/PKG-INFO +0 -299
  23. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/LICENSE +0 -0
  24. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/setup.cfg +0 -0
  25. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen/__main__.py +0 -0
  26. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen/about.py +0 -0
  27. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen/http_debug.py +0 -0
  28. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen/providers/ollama_provider.py +0 -0
  29. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen/ui.py +0 -0
  30. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen_cli.egg-info/dependency_links.txt +0 -0
  31. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen_cli.egg-info/entry_points.txt +0 -0
  32. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen_cli.egg-info/requires.txt +0 -0
  33. {prgen_cli-0.4.0 → prgen_cli-0.5.0}/src/prgen_cli.egg-info/top_level.txt +0 -0
@@ -0,0 +1,441 @@
1
+ Metadata-Version: 2.4
2
+ Name: prgen-cli
3
+ Version: 0.5.0
4
+ Summary: Generate PR titles and descriptions from git diff using LLMs, and open the PR with gh
5
+ Author: Jean Paul Fernandez
6
+ License-Expression: GPL-3.0-only
7
+ Project-URL: Homepage, https://github.com/jpxoi/prgen
8
+ Project-URL: Repository, https://github.com/jpxoi/prgen
9
+ Project-URL: Issues, https://github.com/jpxoi/prgen/issues
10
+ Keywords: cli,git,pull-request,diff,llm,openai,gemini,ollama,claude,codex,github,gh
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Topic :: Software Development :: Version Control
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: google-genai>=1.70.0
21
+ Requires-Dist: ollama>=0.6.1
22
+ Requires-Dist: openai>=2.30.0
23
+ Requires-Dist: rich>=14.3.3
24
+ Requires-Dist: typer>=0.24.1
25
+ Dynamic: license-file
26
+
27
+ # prgen
28
+
29
+ Generate a pull request title and description from `git diff` and commit history.
30
+
31
+ ![prgen CLI help](https://raw.githubusercontent.com/jpxoi/prgen/refs/heads/main/images/help.png)
32
+
33
+ **Author:** Jean Paul Fernandez · [github.com/jpxoi/prgen](https://github.com/jpxoi/prgen)
34
+
35
+ Licensed under the [GNU General Public License v3.0](LICENSE) (GPL-3.0-only).
36
+
37
+ ## Requirements
38
+
39
+ - Python 3.10+
40
+ - `git` on your `PATH`
41
+ - One of:
42
+ - OpenAI API access
43
+ - Google Gemini API access
44
+ - A local or remote Ollama server
45
+ - The [Claude Code](https://claude.com/claude-code) CLI (`claude`), logged in
46
+ - The [Codex](https://github.com/openai/codex) CLI (`codex`), logged in
47
+
48
+ ## Install
49
+
50
+ From [PyPI](https://pypi.org/project/prgen-cli/):
51
+
52
+ ```bash
53
+ pip install prgen-cli
54
+ # or
55
+ uv tool install prgen-cli
56
+ ```
57
+
58
+ From a clone:
59
+
60
+ ```bash
61
+ uv sync
62
+ ```
63
+
64
+ Run the CLI with:
65
+
66
+ ```bash
67
+ prgen --help
68
+ ```
69
+
70
+ ## What It Does
71
+
72
+ `prgen` compares `HEAD` against a base ref, collects:
73
+
74
+ - `git diff <base>...HEAD`, without dependency lockfiles (see below)
75
+ - `git log <base>..HEAD`
76
+
77
+ It sends that context to an LLM and prints:
78
+
79
+ - a PR title from `<summary>...</summary>`
80
+ - a PR description from `<body>...</body>`
81
+
82
+ If the model does not return those tags, prgen prints the raw model output instead.
83
+
84
+ ### Lockfiles
85
+
86
+ Dependency lockfiles are left out of the diff: they are large, generated, and the useful
87
+ part (which dependency changed to which version) already shows up in the manifest diff
88
+ (`pyproject.toml`, `package.json`, `Cargo.toml`, …). prgen only tells the model which
89
+ lockfiles changed, by name and status (for example `uv.lock (modified)`), so it can
90
+ mention a dependency update without reading the file.
91
+
92
+ Left out, at any depth in the repo: `uv.lock`, `poetry.lock`, `pdm.lock`, `Pipfile.lock`,
93
+ `package-lock.json`, `npm-shrinkwrap.json`, `yarn.lock`, `pnpm-lock.yaml`, `bun.lock`,
94
+ `bun.lockb`, `Cargo.lock`, `go.sum`, `Gemfile.lock`, `composer.lock`, `Podfile.lock`,
95
+ `pubspec.lock`, `mix.lock`, `flake.lock`, `gradle.lockfile`.
96
+
97
+ ### Pull request templates
98
+
99
+ If the repository has a default pull request template, prgen asks the model to follow
100
+ it: same headings, order, and checklists, with each section filled from the changes and
101
+ "N/A" where nothing applies. Checklist items are only checked when the changes clearly
102
+ satisfy them.
103
+
104
+ prgen looks where GitHub does, case-insensitive: `.github/`, the repo root, and `docs/`,
105
+ for `pull_request_template.md` (or `.txt`). A `PULL_REQUEST_TEMPLATE/` folder is used only
106
+ when it holds exactly one template, since GitHub has no default among several.
107
+ `--verbose` shows which template was used.
108
+
109
+ ### Language
110
+
111
+ `--lang en|es|fr` (default `en`, or `lang` in the config) sets the language of the title
112
+ and description. Code identifiers, file names, commands, and the headings of a PR template
113
+ are kept as written.
114
+
115
+ ```bash
116
+ prgen --lang es
117
+ prgen config set lang es
118
+ ```
119
+
120
+ ## Providers
121
+
122
+ `prgen` supports five backends:
123
+
124
+ - `openai`
125
+ - `gemini`
126
+ - `ollama`
127
+ - `claude` (Claude Code CLI)
128
+ - `codex` (Codex CLI)
129
+
130
+ `--provider auto` is the default.
131
+
132
+ In `auto` mode:
133
+
134
+ - Gemini is chosen when `GOOGLE_API_KEY` is available
135
+ - otherwise OpenAI is chosen when `OPENAI_API_KEY` is available
136
+ - otherwise the `claude` CLI is used if it is on your `PATH`
137
+ - otherwise the `codex` CLI is used if it is on your `PATH`
138
+ - if none of these is available, prgen exits with an error
139
+
140
+ ### Claude Code and Codex CLIs
141
+
142
+ `--provider claude` and `--provider codex` run the locally installed CLI in
143
+ non-interactive mode, so the request is billed to whatever that CLI is logged in
144
+ with (for example a Claude Pro/Max or ChatGPT subscription). prgen needs no API key.
145
+
146
+ - `claude` runs `claude -p` with no tools and no saved session
147
+ - `codex` runs `codex exec` in a read-only sandbox with an ephemeral session
148
+ - both run in an empty temporary directory and receive the prompt on stdin
149
+ - `claude` defaults to `haiku`; `codex` uses the model from `~/.codex/config.toml`
150
+
151
+ If `ANTHROPIC_API_KEY` is set in your environment, Claude Code uses it instead of your subscription.
152
+
153
+ Ollama is never picked by `auto` and has no built-in default model, but both can be
154
+ configured so plain `prgen` uses it:
155
+
156
+ ```bash
157
+ prgen config set provider ollama
158
+ prgen config set ollama_model llama3.1:8b
159
+ ```
160
+
161
+ Or per run: `prgen --provider ollama --model llama3.1:8b`.
162
+
163
+ ## Models and reasoning effort
164
+
165
+ Each provider has one default model. Override it per run with `--model`, or
166
+ persistently with `<provider>_model` in the config:
167
+
168
+ | Provider | Default model | Config key |
169
+ | --- | --- | --- |
170
+ | `openai` | `gpt-6-luna` | `openai_model` |
171
+ | `gemini` | `gemini-flash-latest` | `gemini_model` |
172
+ | `claude` | `haiku` | `claude_model` |
173
+ | `codex` | from `~/.codex/config.toml` | `codex_model` |
174
+ | `ollama` | none (required) | `ollama_model` |
175
+
176
+ Model resolution: `--model` → `<provider>_model` → built-in default.
177
+
178
+ Where a provider offers an alias that follows its current model, prgen uses it so the
179
+ default doesn't go stale: `gemini-flash-latest` (Google moves it with two weeks' notice)
180
+ and `haiku` (Claude Code). OpenAI has no such alias, so `gpt-6-luna` is pinned.
181
+
182
+ `--effort low|medium|high` (default `low`, or `effort` in the config) sets one
183
+ reasoning level for every provider. prgen sends it only when the model supports it
184
+ and leaves it out otherwise (for example `gpt-4.1`, Gemini 2.5, or Ollama).
185
+ `--verbose` shows the effort actually sent, or `n/a`.
186
+
187
+ Writing a PR summary is light work, so `low` is usually enough. Try `medium` or `high`
188
+ for large or mixed diffs.
189
+
190
+ ## Quick Start
191
+
192
+ OpenAI:
193
+
194
+ ```bash
195
+ prgen config set OPENAI_API_KEY sk-...
196
+ prgen
197
+ ```
198
+
199
+ Gemini:
200
+
201
+ ```bash
202
+ prgen config set GOOGLE_API_KEY your-key
203
+ prgen --provider gemini
204
+ ```
205
+
206
+ Ollama:
207
+
208
+ ```bash
209
+ prgen --provider ollama --model llama3.1:8b
210
+ ```
211
+
212
+ Claude Code or Codex (uses your CLI login):
213
+
214
+ ```bash
215
+ prgen --provider claude
216
+ prgen --provider claude --model sonnet --effort medium
217
+ prgen --provider codex
218
+ ```
219
+
220
+ If the Ollama model is missing locally, let prgen pull it:
221
+
222
+ ```bash
223
+ prgen --provider ollama --model llama3.1:8b --pull
224
+ ```
225
+
226
+ ## Configuration
227
+
228
+ Configuration lives in `~/.config/prgen/config.json`.
229
+
230
+ If `XDG_CONFIG_HOME` is set, prgen uses:
231
+
232
+ ```bash
233
+ $XDG_CONFIG_HOME/prgen/config.json
234
+ ```
235
+
236
+ You can manage the file with:
237
+
238
+ ```bash
239
+ prgen config
240
+ prgen config show
241
+ prgen config path
242
+ ```
243
+
244
+ Supported persisted keys:
245
+
246
+ - `OPENAI_API_KEY`
247
+ - `GOOGLE_API_KEY`
248
+ - `OLLAMA_HOST`
249
+ - `base`
250
+ - `provider`
251
+ - `effort`
252
+ - `lang`
253
+ - `context`
254
+ - `openai_model`, `gemini_model`, `ollama_model`, `claude_model`, `codex_model`
255
+
256
+ Notes:
257
+
258
+ - `OPENAI_API_KEY` and `GOOGLE_API_KEY` are treated as secrets
259
+ - `OLLAMA_HOST` is not secret and is merged into the environment if set
260
+ - `base`, `provider`, `effort`, `lang`, `context`, and the `<provider>_model` keys are
261
+ optional CLI defaults
262
+ - the `tier` key from prgen 0.4 is ignored and dropped on the next write
263
+
264
+ Examples:
265
+
266
+ ```bash
267
+ prgen config
268
+ prgen config set OPENAI_API_KEY sk-...
269
+ prgen config set GOOGLE_API_KEY your-key
270
+ prgen config set OLLAMA_HOST http://127.0.0.1:11434
271
+ prgen config set base origin/main
272
+ prgen config set provider ollama
273
+ prgen config set effort medium
274
+ prgen config set lang es
275
+ prgen config set context "Formal tone, no emojis, at most 5 bullets."
276
+ prgen config set claude_model sonnet
277
+ prgen config set ollama_model llama3.1:8b
278
+ prgen config unset OLLAMA_HOST
279
+ prgen config show
280
+ ```
281
+
282
+ To read a secret value from stdin:
283
+
284
+ ```bash
285
+ prgen config set OPENAI_API_KEY - < key.txt
286
+ ```
287
+
288
+ ## Defaults
289
+
290
+ Built-in defaults:
291
+
292
+ | Option | Default | Notes |
293
+ | --- | --- | --- |
294
+ | `--repo`, `-C` | current directory | Uses the current git repo unless you point elsewhere |
295
+ | `--base` | `origin/main` | The ref must resolve locally |
296
+ | `--provider` | `auto` | Gemini, then OpenAI (API keys), then the `claude` / `codex` CLIs |
297
+ | `--effort` | `low` | Sent only to models that support reasoning effort |
298
+ | `--model` | provider default | `gpt-6-luna` / `gemini-flash-latest` / `haiku` / Codex config; required for Ollama if `ollama_model` is unset |
299
+ | `--context` | unset | Extra context for the model (motivation, focus, tone); sent only when set |
300
+ | `--lang` | `en` | Language of the title and description: `en`, `es`, `fr` |
301
+ | `--pull` | `false` | Only relevant for Ollama |
302
+ | `--verbose`, `-v` | `false` | Print provider, model, effort, token usage, and HTTP headers to stderr |
303
+
304
+ Config-file defaults apply only when you omit the matching flag:
305
+
306
+ - `base` → `--base`
307
+ - `provider` → `--provider`
308
+ - `effort` → `--effort`
309
+ - `lang` → `--lang`
310
+ - `context` → `--context`
311
+ - `<provider>_model` → `--model`
312
+
313
+ Explicit flags always win over the config file. Default models are listed in
314
+ [Models and reasoning effort](#models-and-reasoning-effort).
315
+
316
+ ## Usage
317
+
318
+ Basic usage:
319
+
320
+ ```bash
321
+ prgen
322
+ ```
323
+
324
+ Pick a different base:
325
+
326
+ ```bash
327
+ prgen --base main
328
+ ```
329
+
330
+ Run against another repository:
331
+
332
+ ```bash
333
+ prgen -C ~/src/my-project
334
+ ```
335
+
336
+ Override the model directly:
337
+
338
+ ```bash
339
+ prgen --provider openai --model gpt-6.2-sol
340
+ prgen --provider gemini --model gemini-4-carbon --effort high
341
+ prgen --provider ollama --model mistral-small3.1
342
+ ```
343
+
344
+ Add extra context:
345
+
346
+ ```bash
347
+ prgen --context "Focus on customer-facing impact and rollout notes."
348
+ ```
349
+
350
+ The context is added to the prompt only when you pass it (or set `context` in the
351
+ config). A `--context` flag replaces the saved one for that run.
352
+
353
+ See what prgen actually sent and used (useful on rate-limit errors):
354
+
355
+ ```bash
356
+ prgen --verbose
357
+ ```
358
+
359
+ With `--verbose`, prgen prints to stderr:
360
+
361
+ - provider, model, effort sent (or `n/a`), git base, commit count, and prompt size
362
+ - lockfiles left out of the diff, if any
363
+ - token usage (OpenAI / Gemini / Claude / Codex) or eval counts (Ollama)
364
+ - HTTP status and useful response headers (rate limits, request id) for OpenAI, Gemini,
365
+ and Ollama; the `claude` and `codex` CLIs make their own requests, so no headers are shown
366
+
367
+ Transport headers are omitted. Authorization values and API keys in URLs are redacted.
368
+
369
+ ## Open the Pull Request with `gh`
370
+
371
+ With `--pr`, prgen creates the pull request with the [GitHub CLI](https://cli.github.com)
372
+ using the generated title and description, or updates the open PR for the current branch.
373
+
374
+ ```bash
375
+ prgen --pr # create (or update) the PR, after confirming
376
+ prgen --pr --push # push the branch first if needed
377
+ prgen --pr --draft --reviewer ana --assignee me
378
+ prgen --pr --web # open GitHub's PR form in the browser, prefilled
379
+ prgen --pr --yes # no confirmation prompt (scripts / CI)
380
+ ```
381
+
382
+ | Flag | What it does |
383
+ | --- | --- |
384
+ | `--pr` | Create the PR, or update the open one for this branch |
385
+ | `--push` | Push the branch if it isn't on the remote or has unpushed commits |
386
+ | `--draft` | Open the PR as a draft (ignored when updating) |
387
+ | `--reviewer LOGIN` | Request a review; repeatable or comma-separated |
388
+ | `--assignee LOGIN` | Assign someone; `me` assigns you; repeatable or comma-separated |
389
+ | `--web` | Open the prefilled form (or the updated PR) in the browser |
390
+ | `--yes`, `-y` | Skip the confirmation prompt |
391
+
392
+ How it works:
393
+
394
+ - the checks run **before** the model is called, so a problem doesn't waste a generation:
395
+ `gh` installed and logged in, a branch checked out (not the base), `--base` is a branch
396
+ - prgen never pushes on its own: if the branch isn't on the remote or has unpushed
397
+ commits, it stops and tells you to push, unless you pass `--push`
398
+ - `--base origin/main` becomes `main` for GitHub
399
+ - if the branch already has an open PR, prgen asks before replacing its title and
400
+ description (`gh pr edit`); reviewers and assignees are added, not replaced
401
+ - the "Generated with prgen" footer is not added to the PR body
402
+ - if the model didn't return `<summary>`/`<body>`, no PR is opened
403
+ - without a terminal, `--pr` needs `--yes`
404
+ - GitHub's web form can't prefill reviewers, so `--web` and `--reviewer` can't be combined
405
+
406
+ ## Behavior Notes
407
+
408
+ - prgen validates that `--base` resolves before generating anything
409
+ - if there are no commits and no file changes vs the base ref, prgen exits with an error
410
+ - when `--provider ollama --pull` is used, prgen can download the model automatically
411
+ - when stderr is a TTY, loading states and Ollama downloads use Rich UI output
412
+ - `--verbose` prints usage and, for API providers, response headers after the call (or after an error), including rate-limit metadata when the provider sends it
413
+
414
+ ## Development
415
+
416
+ Install local dependencies:
417
+
418
+ ```bash
419
+ uv sync
420
+ ```
421
+
422
+ Format and lint:
423
+
424
+ ```bash
425
+ uv run ruff format .
426
+ uv run ruff check .
427
+ ```
428
+
429
+ Run from the repo without installing globally:
430
+
431
+ ```bash
432
+ uv run prgen --help
433
+ ```
434
+
435
+ Install the local checkout as a global tool:
436
+
437
+ ```bash
438
+ uv tool install .
439
+ # or
440
+ pipx install .
441
+ ```