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/PLAN.md ADDED
@@ -0,0 +1,378 @@
1
+ # Diffron Project Plan
2
+
3
+ ## Overview
4
+
5
+ **Diffron** generates Git commit messages and PR descriptions using Lemonade via lemonade-python-sdk.
6
+
7
+ **Name Etymology:** `diff` + `-ron` (echoing TabNeuron) — Technical, concise.
8
+
9
+ ---
10
+
11
+ ## Project Structure
12
+
13
+ ```
14
+ diffron/
15
+ ├── diffron/
16
+ │ ├── __init__.py
17
+ │ ├── __init__.pyi
18
+ │ ├── py.typed
19
+ │ ├── client.py # Main DiffronClient class
20
+ │ ├── client.pyi
21
+ │ ├── lemonade.py # Lemonade SDK integration & port detection
22
+ │ ├── lemonade.pyi
23
+ │ ├── git_hooks.py # Git hook installation & management
24
+ │ ├── git_hooks.pyi
25
+ │ ├── commit_gen.py # Commit message generation logic
26
+ │ ├── commit_gen.pyi
27
+ │ ├── pr_gen.py # PR description generation logic
28
+ │ ├── pr_gen.pyi
29
+ │ └── utils.py # Shared utilities
30
+ │ └── utils.pyi
31
+ ├── tests/
32
+ │ ├── __init__.py
33
+ │ ├── test_lemonade.py
34
+ │ ├── test_git_hooks.py
35
+ │ ├── test_commit_gen.py
36
+ │ └── test_pr_gen.py
37
+ ├── hooks/
38
+ │ ├── prepare-commit-msg # Shell wrapper (no extension)
39
+ │ ├── prepare-commit-msg.py # Python hook script
40
+ │ └── aipr.py # PR description generator (manual run)
41
+ ├── docs/
42
+ │ ├── PLAN.md # This file
43
+ │ ├── SETUP.md # Installation & configuration guide
44
+ │ ├── USAGE.md # User documentation
45
+ │ └── API.md # API reference
46
+ ├── .gitignore
47
+ ├── pyproject.toml
48
+ ├── setup.py
49
+ ├── setup.pyi
50
+ ├── README.md
51
+ ├── LICENSE
52
+ └── requirements.txt
53
+ ```
54
+
55
+ ---
56
+
57
+ ## Core Features
58
+
59
+ ### 1. Lemonade Auto-Detection
60
+ - **Port Discovery:** Automatically detect running Lemonade instance
61
+ - **Fallback Ports:** Try common ports (8000, 8001, 8080, etc.)
62
+ - **Connection Validation:** Verify Lemonade is responsive before use
63
+
64
+ ### 2. Git Hook Automation
65
+ - **prepare-commit-msg Hook:** Auto-generates commit messages on `git commit`
66
+ - **Windows-Compatible:** Uses shell wrapper + Python script pattern
67
+ - **GitHub Desktop Ready:** Works with GitHub Desktop 3.5.5+ hooks support
68
+ - **Skip Logic:** Intelligently skips merges, rebases, and empty commits
69
+
70
+ ### 3. Commit Message Generation
71
+ - **Conventional Commits:** Enforces `feat:`, `fix:`, `chore:`, etc. format
72
+ - **Context-Aware:** Analyzes staged diff (up to 4000 chars)
73
+ - **Concise Output:** Max 100 tokens, temperature 0.2 for consistency
74
+
75
+ ### 4. PR Description Generator (`aipr.py`)
76
+ - **Manual Trigger:** Run `diffron-pr` or `python -m diffron.aipr`
77
+ - **Branch Analysis:** Compares branch to main/master
78
+ - **Dual Output:** Generates TITLE + DESCRIPTION format
79
+ - **GitHub CLI Integration:** Auto-creates PR via `gh pr create` if available
80
+
81
+ ---
82
+
83
+ ## Technical Architecture
84
+
85
+ ### Module Dependencies
86
+
87
+ ```
88
+ diffron/
89
+ ├── client.py (Main Entry Point)
90
+ │ └── Uses: lemonade.py, git_hooks.py, commit_gen.py, pr_gen.py
91
+
92
+ ├── lemonade.py (Lemonade Integration)
93
+ │ └── Uses: utils.py (for port scanning)
94
+ │ └── External: openai package (Lemonade API client)
95
+
96
+ ├── git_hooks.py (Hook Management)
97
+ │ └── Uses: utils.py (for path resolution)
98
+ │ └── Installs: hooks/prepare-commit-msg, hooks/prepare-commit-msg.py
99
+
100
+ ├── commit_gen.py (Commit Generation)
101
+ │ └── Uses: lemonade.py, utils.py (for diff extraction)
102
+
103
+ └── pr_gen.py (PR Generation)
104
+ └── Uses: lemonade.py, utils.py (for branch/log extraction)
105
+ ```
106
+
107
+ ### External Dependencies
108
+
109
+ | Package | Version | Purpose |
110
+ |---------|---------|---------|
111
+ | `openai` | >=1.0 | Lemonade API client (compatible with Lemonade's OpenAI-compatible API) |
112
+ | `gitpython` | >=3.1 | Git operations (optional, fallback to subprocess) |
113
+ | `psutil` | >=5.9 | Port scanning for Lemonade detection |
114
+
115
+ ### Lemonade SDK Integration
116
+
117
+ Since Diffron is part of the same ecosystem as `lemonade-python-sdk`, it should:
118
+
119
+ 1. **Import Directly:** `from lemonade_sdk import LemonadeClient`
120
+ 2. **Auto-Configure:** Use SDK's built-in port detection
121
+ 3. **Fallback:** If SDK not installed, use direct OpenAI client with auto-discovery
122
+
123
+ ---
124
+
125
+ ## Implementation Phases
126
+
127
+ ### Phase 1: Core Infrastructure
128
+ - [ ] Create project skeleton (this plan)
129
+ - [ ] Implement `lemonade.py` with port detection
130
+ - [ ] Implement `commit_gen.py` with basic diff analysis
131
+ - [ ] Create shell wrapper + Python hook scripts
132
+ - [ ] Write `git_hooks.py` for installation logic
133
+
134
+ ### Phase 2: PR Generation
135
+ - [ ] Implement `pr_gen.py` for branch analysis
136
+ - [ ] Create `aipr.py` standalone script
137
+ - [ ] Add GitHub CLI integration
138
+ - [ ] Format output as TITLE + DESCRIPTION
139
+
140
+ ### Phase 3: Polish & Packaging
141
+ - [ ] Write comprehensive tests
142
+ - [ ] Create documentation (SETUP.md, USAGE.md, API.md)
143
+ - [ ] Build PyPI package
144
+ - [ ] Add CLI entry points (`diffron-install-hooks`, `diffron-pr`)
145
+
146
+ ### Phase 4: Advanced Features (Future)
147
+ - [ ] Global hooks installation (`--global` flag)
148
+ - [ ] Custom model selection
149
+ - [ ] Commit message templates
150
+ - [ ] Multi-language support
151
+ - [ ] Pre-commit hook for linting suggestions
152
+
153
+ ---
154
+
155
+ ## Windows-Specific Considerations
156
+
157
+ ### Git Hooks on Windows
158
+
159
+ **GitHub Desktop 3.5.5+** officially supports Git hooks. The setup requires:
160
+
161
+ 1. **Shell Wrapper** (`.git/hooks/prepare-commit-msg`):
162
+ ```sh
163
+ #!/C:/Program Files/Git/usr/bin/sh.exe
164
+ python ".git/hooks/prepare-commit-msg.py" "$1" "$2"
165
+ exit 0
166
+ ```
167
+
168
+ 2. **Python Script** (`.git/hooks/prepare-commit-msg.py`):
169
+ - Full logic for commit generation
170
+ - Handles encoding (UTF-8)
171
+ - Graceful error handling
172
+
173
+ ### PATH Issues (Resolved in Desktop 3.5.5)
174
+ - No need for global hooks path workaround
175
+ - Git for Windows bundles proper shell interpreter
176
+ - Python must be in system PATH (user responsibility)
177
+
178
+ ### Encoding
179
+ - All file I/O must use `encoding="utf-8"`
180
+ - Git diff output may contain non-ASCII characters
181
+ - Use `errors="ignore"` for subprocess output
182
+
183
+ ---
184
+
185
+ ## API Design
186
+
187
+ ### DiffronClient
188
+
189
+ ```python
190
+ from diffron import DiffronClient
191
+
192
+ client = DiffronClient()
193
+
194
+ # Auto-detect Lemonade
195
+ port = client.detect_lemonade_port() # Returns 8000 or None
196
+
197
+ # Generate commit message
198
+ commit_msg = client.generate_commit_message(diff=diff_text)
199
+
200
+ # Generate PR description
201
+ pr = client.generate_pr_description(branch="feature/my-branch")
202
+ print(f"TITLE: {pr.title}")
203
+ print(f"DESCRIPTION: {pr.description}")
204
+
205
+ # Install hooks
206
+ client.install_hooks(repo_path=".")
207
+ ```
208
+
209
+ ### CLI Entry Points
210
+
211
+ ```bash
212
+ # Install hooks to current repo
213
+ diffron-install-hooks
214
+
215
+ # Install hooks globally
216
+ diffron-install-hooks --global
217
+
218
+ # Generate PR description manually
219
+ diffron-pr
220
+
221
+ # Check Lemonade status
222
+ diffron-status
223
+ ```
224
+
225
+ ---
226
+
227
+ ## Hook Script Specifications
228
+
229
+ ### prepare-commit-msg (Shell Wrapper)
230
+
231
+ **Location:** `.git/hooks/prepare-commit-msg` (no extension)
232
+
233
+ **Purpose:** Git calls this file; it delegates to Python script.
234
+
235
+ **Content:**
236
+ ```sh
237
+ #!/C:/Program Files/Git/usr/bin/sh.exe
238
+ python ".git/hooks/prepare-commit-msg.py" "$1" "$2"
239
+ exit 0
240
+ ```
241
+
242
+ ### prepare-commit-msg.py (Python Hook)
243
+
244
+ **Location:** `.git/hooks/prepare-commit-msg.py`
245
+
246
+ **Purpose:** Generates commit message from staged diff.
247
+
248
+ **Logic Flow:**
249
+ 1. Parse arguments: `commit_msg_file`, `commit_source`
250
+ 2. Skip if source is `merge`, `squash`, or `commit`
251
+ 3. Get staged diff: `git diff --cached` (max 4000 chars)
252
+ 4. Exit if diff is empty
253
+ 5. Call Lemonade API with diff context
254
+ 6. Write generated message to file
255
+
256
+ ### aipr.py (PR Generator)
257
+
258
+ **Location:** Project root or installed to PATH
259
+
260
+ **Purpose:** Manually generate PR title + description.
261
+
262
+ **Logic Flow:**
263
+ 1. Get current branch name
264
+ 2. Get commit log: `git log --oneline main..HEAD`
265
+ 3. Get diff: `git diff main..HEAD` (max 5000 chars)
266
+ 4. Call Lemonade API with context
267
+ 5. Parse TITLE + DESCRIPTION from response
268
+ 6. Optionally create PR via `gh pr create`
269
+
270
+ ---
271
+
272
+ ## Testing Strategy
273
+
274
+ ### Unit Tests
275
+ - `test_lemonade.py`: Port detection, API client
276
+ - `test_commit_gen.py`: Message generation logic
277
+ - `test_pr_gen.py`: PR description formatting
278
+ - `test_git_hooks.py`: Hook installation paths
279
+
280
+ ### Integration Tests
281
+ - End-to-end commit message generation
282
+ - PR description with real Git repo
283
+ - Lemonade connection (mock or skip if unavailable)
284
+
285
+ ### Test Fixtures
286
+ - Sample diffs (small, medium, large)
287
+ - Sample Git logs
288
+ - Mock Lemonade responses
289
+
290
+ ---
291
+
292
+ ## Documentation Plan
293
+
294
+ ### SETUP.md
295
+ - Prerequisites (Python, Git, GitHub Desktop version)
296
+ - Lemonade installation & setup
297
+ - Diffron installation (`pip install diffron`)
298
+ - Hook installation (per-repo and global)
299
+ - Troubleshooting (common Windows issues)
300
+
301
+ ### USAGE.md
302
+ - Basic workflow (commit, push, PR)
303
+ - CLI commands reference
304
+ - Customization options
305
+ - Examples with screenshots
306
+
307
+ ### API.md
308
+ - `DiffronClient` class reference
309
+ - Method signatures & return types
310
+ - Error handling
311
+ - Extension points
312
+
313
+ ---
314
+
315
+ ## Success Criteria
316
+
317
+ 1. **Functional:**
318
+ - Hooks install successfully on Windows
319
+ - Commit messages auto-generated on `git commit`
320
+ - PR descriptions generated with `diffron-pr`
321
+ - Lemonade auto-detection works reliably
322
+
323
+ 2. **User Experience:**
324
+ - Zero-config for users with Lemonade running
325
+ - Clear error messages if Lemonade not found
326
+ - Seamless GitHub Desktop integration
327
+
328
+ 3. **Code Quality:**
329
+ - Type hints throughout (`.pyi` stubs)
330
+ - Test coverage >80%
331
+ - PEP 8 compliant
332
+ - Comprehensive docstrings
333
+
334
+ ---
335
+
336
+ ## Future Enhancements
337
+
338
+ - **Pre-commit Hook:** AI-powered linting suggestions
339
+ - **Review Assistant:** Auto-generate code review comments
340
+ - **Commit Summarizer:** Summarize multiple commits for squash
341
+ - **Multi-Model Support:** Let users choose model for generation
342
+ - **Offline Mode:** Cache responses for common patterns
343
+ - **Slack/Teams Integration:** Post commit summaries to channels
344
+
345
+ ---
346
+
347
+ ## Related Projects
348
+
349
+ ```
350
+ ┌─────────────────────────────────────────────────────┐
351
+ │ Aicono │ AI Assistant (Desktop App) │
352
+ │ TabNeuron │ Browser Connector / Memory │
353
+ │ Sorana │ Advanced AI Interface │
354
+ │ RyzenPilot │ Hardware Optimization │
355
+ │ lemonade-sdk │ Python SDK for AMD Lemonade API │
356
+ │ Diffron │ Git Commit/PR Generator │
357
+ └─────────────────────────────────────────────────────┘
358
+ ```
359
+
360
+ Note: Lemonade is AMD's local LLM server. Diffron uses lemonade-python-sdk to communicate with Lemonade's API.
361
+
362
+ ---
363
+
364
+ ## Next Steps
365
+
366
+ 1. **Initialize Git Repo:** `git init` in project folder
367
+ 2. **Create Package Skeleton:** Run `python -m diffron` scaffold
368
+ 3. **Implement lemonade.py:** Port detection + API client
369
+ 4. **Implement commit_gen.py:** Basic commit generation
370
+ 5. **Create Hook Scripts:** Shell wrapper + Python script
371
+ 6. **Test End-to-End:** Verify with real Git repo + Lemonade
372
+ 7. **Write Docs:** SETUP.md, USAGE.md
373
+ 8. **Publish to PyPI:** First release v0.1.0
374
+
375
+ ---
376
+
377
+ *Document created: 2026-03-28*
378
+ *Project: Diffron v0.1.0 (Planning Phase)*