diffron 0.1.0__py3-none-any.whl

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.
docs/USAGE.md ADDED
@@ -0,0 +1,515 @@
1
+ # Diffron Usage Guide
2
+
3
+ This guide provides detailed usage examples for Diffron's CLI and Python API.
4
+
5
+ ---
6
+
7
+ ## Table of Contents
8
+
9
+ 1. [CLI Commands](#cli-commands)
10
+ 2. [Python API](#python-api)
11
+ 3. [Git Hooks Workflow](#git-hooks-workflow)
12
+ 4. [PR Workflow](#pr-workflow)
13
+ 5. [Advanced Usage](#advanced-usage)
14
+
15
+ ---
16
+
17
+ ## CLI Commands
18
+
19
+ ### `diffron-install-hooks`
20
+
21
+ Install Git hooks to automatically generate commit messages.
22
+
23
+ ```bash
24
+ # Install to current repository
25
+ diffron-install-hooks
26
+
27
+ # Install to specific repository
28
+ diffron-install-hooks --repo /path/to/repo
29
+
30
+ # Install globally (all repositories)
31
+ diffron-install-hooks --global
32
+ ```
33
+
34
+ ### `diffron-uninstall-hooks`
35
+
36
+ Remove Git hooks from a repository.
37
+
38
+ ```bash
39
+ # Uninstall from current repository
40
+ diffron-uninstall-hooks
41
+
42
+ # Uninstall from specific repository
43
+ diffron-uninstall-hooks --repo /path/to/repo
44
+
45
+ # Uninstall global hooks
46
+ diffron-uninstall-hooks --global
47
+ ```
48
+
49
+ ### `diffron-pr`
50
+
51
+ Generate PR title and description.
52
+
53
+ ```bash
54
+ # Generate for current branch
55
+ diffron-pr
56
+
57
+ # Generate for specific branch
58
+ diffron-pr --branch feature/my-feature
59
+
60
+ # Specify base branch
61
+ diffron-pr --base develop
62
+
63
+ # Generate and create PR on GitHub (requires gh CLI)
64
+ diffron-pr --create
65
+ ```
66
+
67
+ ### `diffron-status`
68
+
69
+ Check Diffron status (Lemonade connection, hooks installation).
70
+
71
+ ```bash
72
+ # Quick status
73
+ diffron-status
74
+
75
+ # Detailed status
76
+ diffron-status --verbose
77
+
78
+ # Check specific repository
79
+ diffron-status --repo /path/to/repo
80
+ ```
81
+
82
+ ---
83
+
84
+ ## Python API
85
+
86
+ ### Basic Usage
87
+
88
+ ```python
89
+ from diffron import DiffronClient
90
+
91
+ # Create client (auto-detects Lemonade)
92
+ client = DiffronClient()
93
+
94
+ # Generate commit message from staged diff
95
+ commit_msg = client.generate_commit_message()
96
+ print(commit_msg) # "feat: add user authentication"
97
+
98
+ # Generate PR description
99
+ pr = client.generate_pr_description(branch="feature/my-feature")
100
+ print(f"TITLE: {pr.title}")
101
+ print(f"DESCRIPTION: {pr.description}")
102
+
103
+ # Install hooks
104
+ client.install_hooks(repo_path=".")
105
+ ```
106
+
107
+ ### Lemonade Client
108
+
109
+ ```python
110
+ from diffron import LemonadeClient, detect_lemonade_port
111
+
112
+ # Detect Lemonade port
113
+ port = detect_lemonade_port()
114
+ print(f"Lemonade running on port: {port}") # 8000
115
+
116
+ # Create client with specific settings
117
+ client = LemonadeClient(
118
+ host="localhost",
119
+ port=8000,
120
+ model="your-model-name",
121
+ )
122
+
123
+ # Generate chat completion
124
+ response = client.chat_completion(
125
+ messages=[
126
+ {"role": "system", "content": "You are a helpful assistant."},
127
+ {"role": "user", "content": "Hello!"}
128
+ ],
129
+ max_tokens=50,
130
+ temperature=0.5,
131
+ )
132
+ print(response)
133
+ ```
134
+
135
+ ### Commit Message Generation
136
+
137
+ ```python
138
+ from diffron import generate_commit_message
139
+
140
+ # Generate from staged diff (automatic)
141
+ msg = generate_commit_message()
142
+
143
+ # Generate from custom diff
144
+ custom_diff = """
145
+ diff --git a/src/main.py b/src/main.py
146
+ +def hello():
147
+ + print("Hello, World!")
148
+ """
149
+ msg = generate_commit_message(diff=custom_diff)
150
+
151
+ # With custom parameters
152
+ msg = generate_commit_message(
153
+ diff=custom_diff,
154
+ max_chars=2000, # Limit diff size
155
+ max_tokens=50, # Limit response length
156
+ temperature=0.1, # More deterministic
157
+ )
158
+ ```
159
+
160
+ ### PR Description Generation
161
+
162
+ ```python
163
+ from diffron import generate_pr_description, PRDescription
164
+
165
+ # Generate for current branch
166
+ pr = generate_pr_description()
167
+
168
+ # Generate for specific branch
169
+ pr = generate_pr_description(
170
+ branch="feature/my-feature",
171
+ base="main",
172
+ )
173
+
174
+ # Access properties
175
+ print(f"Title: {pr.title}")
176
+ print(f"Description: {pr.description}")
177
+
178
+ # Format output
179
+ print(pr.format_output())
180
+
181
+ # Get GitHub CLI format
182
+ title, body = pr.to_github_cli()
183
+ ```
184
+
185
+ ### Git Hooks Management
186
+
187
+ ```python
188
+ from diffron import install_hooks, uninstall_hooks, is_hooks_installed
189
+
190
+ # Install hooks
191
+ install_hooks(repo_path=".")
192
+ install_hooks(repo_path="/path/to/repo")
193
+ install_hooks(global_install=True) # Global installation
194
+
195
+ # Check if installed
196
+ if is_hooks_installed():
197
+ print("Hooks are installed!")
198
+
199
+ # Uninstall hooks
200
+ uninstall_hooks(repo_path=".")
201
+ uninstall_hooks(global_install=True) # Remove global hooks
202
+
203
+ # Get detailed status
204
+ from diffron import get_hooks_status
205
+ status = get_hooks_status()
206
+ print(status)
207
+ # {
208
+ # 'is_git_repo': True,
209
+ # 'local_hooks_installed': True,
210
+ # 'global_hooks_configured': False,
211
+ # ...
212
+ # }
213
+ ```
214
+
215
+ ---
216
+
217
+ ## Git Hooks Workflow
218
+
219
+ ### Automatic Commit Messages
220
+
221
+ Once hooks are installed, commit messages are generated automatically:
222
+
223
+ ```bash
224
+ # Make changes
225
+ echo "new feature" >> feature.py
226
+ git add feature.py
227
+
228
+ # Commit - hooks generate the message
229
+ git commit
230
+
231
+ # Result: "feat: add new feature" (auto-generated)
232
+ ```
233
+
234
+ ### Skip Auto-Generation
235
+
236
+ Hooks automatically skip:
237
+ - Merge commits
238
+ - Rebase operations
239
+ - Amend commits (`git commit --amend`)
240
+ - Empty commits
241
+
242
+ To manually write a commit message when hooks are installed:
243
+
244
+ ```bash
245
+ # Use -m flag to provide message directly
246
+ git commit -m "chore: manual commit message"
247
+
248
+ # Or edit the generated message
249
+ git commit # Opens editor with generated message
250
+ ```
251
+
252
+ ### Hook Behavior
253
+
254
+ The `prepare-commit-msg` hook:
255
+
256
+ 1. **Checks Lemonade:** Silently exits if Lemonade is not running
257
+ 2. **Analyzes Diff:** Gets staged changes (max 4000 chars)
258
+ 3. **Generates Message:** Calls Lemonade API
259
+ 4. **Writes Message:** Populates commit message file
260
+ 5. **Opens Editor:** Git opens editor with generated message (default behavior)
261
+
262
+ To skip the editor and commit directly:
263
+
264
+ ```bash
265
+ git commit -m "auto" # Hook replaces "auto" with generated message
266
+ ```
267
+
268
+ ---
269
+
270
+ ## PR Workflow
271
+
272
+ ### Standard Workflow
273
+
274
+ 1. **Create feature branch:**
275
+ ```bash
276
+ git checkout -b feature/my-feature
277
+ ```
278
+
279
+ 2. **Make commits:**
280
+ ```bash
281
+ # Diffron auto-generates commit messages
282
+ git add .
283
+ git commit
284
+ ```
285
+
286
+ 3. **Generate PR description:**
287
+ ```bash
288
+ diffron-pr
289
+ ```
290
+
291
+ 4. **Copy output and create PR:**
292
+ - Copy TITLE and DESCRIPTION
293
+ - Go to GitHub
294
+ - Create PR with copied content
295
+
296
+ ### Automated Workflow (with GitHub CLI)
297
+
298
+ 1. **Install GitHub CLI:**
299
+ ```bash
300
+ # Windows (winget)
301
+ winget install GitHub.cli
302
+
303
+ # Or download from https://cli.github.com/
304
+ ```
305
+
306
+ 2. **Authenticate:**
307
+ ```bash
308
+ gh auth login
309
+ ```
310
+
311
+ 3. **Generate and create PR:**
312
+ ```bash
313
+ diffron-pr --create
314
+ ```
315
+
316
+ ### Manual PR Script
317
+
318
+ Use the standalone `aipr.py` script:
319
+
320
+ ```bash
321
+ # From hooks directory
322
+ python hooks/aipr.py
323
+
324
+ # With branch arguments
325
+ python hooks/aipr.py feature/my-feature main
326
+ ```
327
+
328
+ ---
329
+
330
+ ## Advanced Usage
331
+
332
+ ### Custom Commit Types
333
+
334
+ Diffron uses Conventional Commits by default. To customize:
335
+
336
+ ```python
337
+ from diffron.commit_gen import COMMIT_TYPES, format_commit_message
338
+
339
+ # View available types
340
+ print(COMMIT_TYPES)
341
+ # ['feat', 'fix', 'docs', 'style', 'refactor', 'perf', 'test', 'build', 'ci', 'chore', 'revert']
342
+
343
+ # Format with scope and breaking change
344
+ msg = format_commit_message(
345
+ commit_type="feat",
346
+ description="change API structure",
347
+ scope="api",
348
+ breaking=True,
349
+ )
350
+ print(msg) # "feat(api)!: change API structure"
351
+ ```
352
+
353
+ ### Batch Operations
354
+
355
+ ```python
356
+ from diffron import DiffronClient
357
+
358
+ client = DiffronClient()
359
+
360
+ # Process multiple repositories
361
+ repos = ["/path/to/repo1", "/path/to/repo2"]
362
+
363
+ for repo in repos:
364
+ print(f"Processing {repo}...")
365
+ client.install_hooks(repo_path=repo)
366
+ ```
367
+
368
+ ### Integration with CI/CD
369
+
370
+ Use Diffron in CI pipelines:
371
+
372
+ ```yaml
373
+ # GitHub Actions example
374
+ name: PR Description
375
+ on:
376
+ pull_request:
377
+ types: [opened]
378
+
379
+ jobs:
380
+ generate-pr:
381
+ runs-on: ubuntu-latest
382
+ steps:
383
+ - uses: actions/checkout@v3
384
+ - name: Install Diffron
385
+ run: pip install diffron
386
+ - name: Generate PR description
387
+ run: diffron-pr
388
+ env:
389
+ DIFFRON_LEMONADE_HOST: ${{ secrets.LEMONADE_HOST }}
390
+ ```
391
+
392
+ ### Custom Prompts
393
+
394
+ Modify the prompt for commit generation:
395
+
396
+ ```python
397
+ from diffron.lemonade import LemonadeClient
398
+
399
+ client = LemonadeClient()
400
+
401
+ custom_prompt = """
402
+ Analyze this git diff and write a commit message.
403
+ Focus on the user-facing changes.
404
+ Format: type(scope): description
405
+
406
+ Diff:
407
+ """ + diff
408
+
409
+ response = client.chat_completion(
410
+ messages=[{"role": "user", "content": custom_prompt}],
411
+ max_tokens=100,
412
+ temperature=0.2,
413
+ )
414
+ ```
415
+
416
+ ---
417
+
418
+ ## Tips and Best Practices
419
+
420
+ ### 1. Review Generated Messages
421
+
422
+ Always review auto-generated commit messages before committing:
423
+
424
+ ```bash
425
+ git commit # Opens editor with generated message
426
+ # Review and save, or modify as needed
427
+ ```
428
+
429
+ ### 2. Use Scopes for Large Projects
430
+
431
+ For projects with multiple components:
432
+
433
+ ```bash
434
+ # Generated: "feat(api): add user endpoint"
435
+ # Generated: "fix(ui): resolve button alignment"
436
+ ```
437
+
438
+ ### 3. Keep Changes Focused
439
+
440
+ Smaller, focused commits generate better messages:
441
+
442
+ ```bash
443
+ # Good: Single feature
444
+ git add src/auth.py
445
+ git commit # "feat: add authentication"
446
+
447
+ # Better than: Multiple unrelated changes
448
+ git add .
449
+ git commit # Generic message
450
+ ```
451
+
452
+ ### 4. Combine with Pre-commit Hooks
453
+
454
+ Use Diffron alongside pre-commit hooks:
455
+
456
+ ```yaml
457
+ # .pre-commit-config.yaml
458
+ repos:
459
+ - repo: https://github.com/pre-commit/pre-commit-hooks
460
+ rev: v4.0.0
461
+ hooks:
462
+ - id: trailing-whitespace
463
+ - id: end-of-file-fixer
464
+ # Diffron handles commit messages separately
465
+ ```
466
+
467
+ ---
468
+
469
+ ## Examples
470
+
471
+ ### Example 1: Feature Development
472
+
473
+ ```bash
474
+ # Start feature branch
475
+ git checkout -b feat/user-auth
476
+
477
+ # Make changes and commit (auto-generated messages)
478
+ git add src/auth.py
479
+ git commit # "feat: add user authentication"
480
+
481
+ git add tests/test_auth.py
482
+ git commit # "test: add authentication tests"
483
+
484
+ # Generate PR description
485
+ diffron-pr --create
486
+ ```
487
+
488
+ ### Example 2: Bug Fix
489
+
490
+ ```bash
491
+ # Create fix branch
492
+ git checkout -b fix/login-bug
493
+
494
+ # Fix the bug
495
+ git add src/login.py
496
+ git commit # "fix: resolve login redirect issue"
497
+
498
+ # Generate PR
499
+ diffron-pr --base main
500
+ ```
501
+
502
+ ### Example 3: Documentation Update
503
+
504
+ ```bash
505
+ # Update docs
506
+ git add docs/*.md
507
+ git commit # "docs: update installation guide"
508
+
509
+ # No PR needed for docs-only changes
510
+ git push origin main
511
+ ```
512
+
513
+ ---
514
+
515
+ *Last updated: 2026-03-28*