patchwork-conventions 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.
@@ -0,0 +1,393 @@
1
+ Metadata-Version: 2.4
2
+ Name: patchwork-conventions
3
+ Version: 0.1.0
4
+ Summary: Mine your codebase. Generate CONVENTIONS.md. Stop AI agents from making up your style.
5
+ Author: patchwork contributors
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/yourusername/patchwork
8
+ Project-URL: Repository, https://github.com/yourusername/patchwork
9
+ Project-URL: Issues, https://github.com/yourusername/patchwork/issues
10
+ Keywords: ai,claude-code,conventions,code-style,context-engineering,mcp,agent-skills,static-analysis,tree-sitter
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Programming Language :: Python :: 3.9
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
20
+ Classifier: Topic :: Software Development :: Quality Assurance
21
+ Requires-Python: >=3.9
22
+ Description-Content-Type: text/markdown
23
+ License-File: LICENSE
24
+ Requires-Dist: click>=8.0
25
+ Requires-Dist: rich>=13.0
26
+ Requires-Dist: tree-sitter>=0.23
27
+ Requires-Dist: tree-sitter-python>=0.23
28
+ Requires-Dist: tree-sitter-javascript>=0.23
29
+ Requires-Dist: tree-sitter-typescript>=0.23
30
+ Requires-Dist: mcp>=1.0
31
+ Requires-Dist: gitpython>=3.1
32
+ Requires-Dist: pathspec>=0.11
33
+ Requires-Dist: toml>=0.10; python_version < "3.11"
34
+ Provides-Extra: dev
35
+ Requires-Dist: pytest>=7.0; extra == "dev"
36
+ Requires-Dist: pytest-asyncio; extra == "dev"
37
+ Requires-Dist: black; extra == "dev"
38
+ Requires-Dist: ruff; extra == "dev"
39
+ Requires-Dist: mypy; extra == "dev"
40
+ Provides-Extra: full
41
+ Requires-Dist: tree-sitter-rust>=0.23; extra == "full"
42
+ Requires-Dist: tree-sitter-go>=0.23; extra == "full"
43
+ Requires-Dist: tree-sitter-java>=0.23; extra == "full"
44
+ Dynamic: license-file
45
+
46
+ # patchwork
47
+
48
+ **Mine your codebase. Generate CONVENTIONS.md. Stop AI agents from making up your style.**
49
+
50
+ [![PyPI](https://img.shields.io/pypi/v/patchwork-conventions)](https://pypi.org/project/patchwork-conventions/)
51
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
52
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
53
+ [![agent-skills](https://img.shields.io/badge/agent--skills-compatible-brightgreen)](https://github.com/topics/agent-skills)
54
+ [![MCP](https://img.shields.io/badge/MCP-server-blue)](https://github.com/topics/mcp)
55
+
56
+ ---
57
+
58
+ Every team that uses AI coding assistants hits the same wall: **Claude writes `getUserById` in a codebase that uses `get_user_by_id`. Cursor creates `components/userCard.tsx` in a project that uses `user-card.tsx`. The agent invented a response shape that doesn't match the rest of the API.**
59
+
60
+ You write a `CLAUDE.md` manually. It goes stale in two weeks. You write it again.
61
+
62
+ **patchwork automates this.** It scans your actual source code using AST analysis and detects what your team really does — not what you think you do.
63
+
64
+ ---
65
+
66
+ ## What it detects
67
+
68
+ | Category | What's mined |
69
+ |---|---|
70
+ | **Naming** | Functions, classes, variables, constants, files — with confidence score and real examples |
71
+ | **Imports** | Absolute vs relative, path aliases (`@/`, `src/`), barrel files, destructuring style |
72
+ | **Structure** | Source root, test layout, feature vs layer organisation, monorepo detection |
73
+ | **Error Handling** | try/except vs Result types, logging framework, custom exception naming, propagation style |
74
+ | **Testing** | Framework, assertion style, mocking library, coverage tool, fixture patterns |
75
+ | **API Patterns** | Response shape, route param style, ORM, async pattern, GraphQL/gRPC presence |
76
+ | **Git Workflow** | Commit message style, branch naming, co-change file pairs |
77
+ | **Tech Stack** | Frameworks, package manager, linters, formatters, type checker, build tool, scripts |
78
+
79
+ ---
80
+
81
+ ## Quick start
82
+
83
+ ```bash
84
+ pip install patchwork-conventions
85
+ cd your-project
86
+ patchwork scan
87
+ ```
88
+
89
+ That's it. You'll get a `CONVENTIONS.md` like this:
90
+
91
+ ```markdown
92
+ # CONVENTIONS.md
93
+ > Auto-generated by patchwork on 2026-06-25
94
+
95
+ ## Tech Stack
96
+ **Language:** python
97
+ **Runtime:** Python >=3.11
98
+ **Package Manager:** uv
99
+ **Frameworks:** fastapi, sqlalchemy
100
+ **Linters:** ruff
101
+ **Formatters:** ruff, black
102
+
103
+ ## Naming Conventions
104
+
105
+ ### Python
106
+ - **Functions:** `snake_case` (97% consistent)
107
+ - Examples: `get_user`, `parse_response`, `create_session`
108
+ - **Classes:** `PascalCase` (100% consistent)
109
+ - Examples: `UserService`, `AuthHandler`, `DatabaseClient`
110
+ - **Constants:** `SCREAMING_SNAKE`
111
+ - Examples: `MAX_RETRIES`, `API_BASE_URL`
112
+ - **Files:** `snake_case`
113
+ - **Private prefix:** `_`
114
+ - **Test functions:** prefix `test_`
115
+
116
+ ## Project Structure
117
+ **Source root:** `src/`
118
+ **Organisation:** layer-based
119
+ **Tests:** separate (`tests/`)
120
+
121
+ **Key directories:**
122
+ - `src/` — source root
123
+ - `tests/` — test suite
124
+ - `migrations/` — database migrations
125
+
126
+ ## Error Handling
127
+
128
+ ### Python
129
+ - **Pattern:** try/except
130
+ - **Propagation:** raise
131
+ - **Logging:** `structlog`
132
+ - **Custom exception naming:** Error suffix
133
+ - `ValidationError`, `AuthError`, `NotFoundError`
134
+
135
+ ## Testing Conventions
136
+
137
+ ### Python
138
+ - **Framework:** pytest
139
+ - **Coverage:** 34 test files / 89 source files (38% ratio)
140
+ - **Assertions:** `assert(...)`
141
+ - **Coverage tool:** `pytest-cov`
142
+ - **Patterns:** fixtures, factories
143
+
144
+ ## Git Conventions
145
+ - **Commit style:** conventional commits
146
+ - **Examples:** `feat(auth): add JWT refresh`, `fix(api): handle null user`
147
+ - **Branch naming:** feature/name + fix/name
148
+ ```
149
+
150
+ ---
151
+
152
+ ## Why not argus or sourcebook?
153
+
154
+ | Feature | patchwork | argus | sourcebook |
155
+ |---|---|---|---|
156
+ | AST-based naming analysis | ✅ tree-sitter | ❌ filesystem only | ❌ not done |
157
+ | Confidence scores | ✅ per-category | ❌ | ❌ |
158
+ | Real examples from your code | ✅ | ❌ | ❌ |
159
+ | Counter-examples (inconsistencies) | ✅ | ❌ | ❌ |
160
+ | Error handling pattern mining | ✅ | ❌ | ❌ |
161
+ | API response shape detection | ✅ | ❌ | ❌ |
162
+ | Co-change file pairs | ✅ | ❌ | ✅ |
163
+ | Convention checking (`check` cmd) | ✅ | ❌ | ❌ |
164
+ | MCP server with 8 tools | ✅ | ❌ | ✅ (4 tools) |
165
+ | Watch mode | ✅ | ✅ (`sync`) | ✅ |
166
+ | Zero LLM required | ✅ | ✅ | ✅ (layer A) |
167
+ | Open source / MIT | ✅ | ✅ | ❌ BSL |
168
+
169
+ ---
170
+
171
+ ## Commands
172
+
173
+ ```bash
174
+ # Generate CONVENTIONS.md
175
+ patchwork scan
176
+
177
+ # Generate for a specific path
178
+ patchwork scan /path/to/project
179
+
180
+ # Generate AGENTS.md
181
+ patchwork scan --agents-md
182
+
183
+ # Append to CLAUDE.md
184
+ patchwork scan --claude-md
185
+
186
+ # Output JSON (for programmatic use)
187
+ patchwork scan --json
188
+
189
+ # Print to stdout (don't write file)
190
+ patchwork scan --stdout
191
+
192
+ # Limit to specific languages
193
+ patchwork scan --lang python --lang typescript
194
+
195
+ # Re-scan and update, preserving manual edits
196
+ patchwork update
197
+
198
+ # Show what would change
199
+ patchwork diff
200
+
201
+ # Print detected conventions to terminal
202
+ patchwork show
203
+
204
+ # Auto-watch mode (regenerate on change)
205
+ patchwork watch
206
+
207
+ # Start MCP server
208
+ patchwork serve --stdio # for Claude Code
209
+ patchwork serve --port 3742 # HTTP mode
210
+ ```
211
+
212
+ ---
213
+
214
+ ## Claude Code integration
215
+
216
+ ### Option 1: CONVENTIONS.md (recommended)
217
+
218
+ ```bash
219
+ patchwork scan # run once
220
+ # CONVENTIONS.md is automatically read by Claude Code
221
+ ```
222
+
223
+ ### Option 2: Append to CLAUDE.md
224
+
225
+ ```bash
226
+ patchwork scan --claude-md
227
+ ```
228
+
229
+ ### Option 3: MCP server
230
+
231
+ Add to `~/.claude/settings.json`:
232
+
233
+ ```json
234
+ {
235
+ "mcpServers": {
236
+ "patchwork": {
237
+ "command": "patchwork",
238
+ "args": ["serve", "--stdio", "/path/to/your/project"]
239
+ }
240
+ }
241
+ }
242
+ ```
243
+
244
+ Then Claude Code can use 8 on-demand tools:
245
+
246
+ | Tool | When to use |
247
+ |---|---|
248
+ | `patchwork_scan` | Get complete conventions overview |
249
+ | `patchwork_naming` | Before writing new identifiers |
250
+ | `patchwork_structure` | Before creating new files/directories |
251
+ | `patchwork_stack` | When choosing libraries or commands |
252
+ | `patchwork_errors` | Before writing error handling |
253
+ | `patchwork_testing` | Before writing test files |
254
+ | `patchwork_git` | Before writing commit messages |
255
+ | `patchwork_check` | Validate a proposed name |
256
+
257
+ ### Option 4: Claude Code skill (SKILL.md)
258
+
259
+ Copy `SKILL.md` from this repo to `~/.claude/skills/patchwork/SKILL.md` to get `/patchwork` slash commands.
260
+
261
+ ---
262
+
263
+ ## Watch mode (CI/auto-update)
264
+
265
+ ```bash
266
+ # Keep CONVENTIONS.md updated as you code
267
+ patchwork watch &
268
+
269
+ # Or in CI — fail if conventions changed
270
+ patchwork diff || (patchwork update && git add CONVENTIONS.md && git commit -m "chore: update conventions")
271
+ ```
272
+
273
+ ---
274
+
275
+ ## Python API
276
+
277
+ ```python
278
+ from patchwork import scan
279
+ from patchwork.scanner import ScanOptions
280
+ from pathlib import Path
281
+
282
+ # Full scan
283
+ report = scan(ScanOptions(root=Path(".")))
284
+
285
+ # Render to markdown
286
+ print(report.to_markdown())
287
+
288
+ # Render to JSON
289
+ import json
290
+ data = json.loads(report.to_json())
291
+
292
+ # Access specific results
293
+ naming = report.naming.get("python")
294
+ print(f"Functions: {naming.functions.style} ({naming.functions.confidence:.0%})")
295
+ print(f"Examples: {naming.functions.examples}")
296
+
297
+ structure = report.structure
298
+ print(f"Source root: {structure.source_root}")
299
+ print(f"Organisation: {structure.organisation}")
300
+ ```
301
+
302
+ ---
303
+
304
+ ## Supported languages
305
+
306
+ | Language | AST (tree-sitter) | Fallback regex |
307
+ |---|---|---|
308
+ | Python | ✅ full | ✅ |
309
+ | TypeScript | ✅ full | ✅ |
310
+ | JavaScript | ✅ full | ✅ |
311
+ | Go | ✅ (with `full` extra) | ✅ |
312
+ | Rust | ✅ (with `full` extra) | ✅ |
313
+ | Java | ✅ (with `full` extra) | ✅ |
314
+ | Ruby, PHP, C#, C++ | ❌ | ✅ regex only |
315
+
316
+ Install full language support:
317
+
318
+ ```bash
319
+ pip install 'patchwork-conventions[full]'
320
+ ```
321
+
322
+ ---
323
+
324
+ ## How it works
325
+
326
+ ```
327
+ your codebase
328
+
329
+
330
+ ConfigDetector ← reads package.json, pyproject.toml, go.mod, Cargo.toml
331
+
332
+
333
+ File discovery ← respects .gitignore, skips node_modules etc.
334
+
335
+
336
+ Per-language AST ← tree-sitter parses every file into a syntax tree
337
+
338
+ ├── NamingMiner → extracts function/class/variable names, classifies style
339
+ ├── ImportMiner → detects import patterns, aliases, barrel files
340
+ ├── StructureMiner → analyses directory layout, test co-location
341
+ ├── ErrorHandlingMiner → detects try/catch patterns, logging, custom exceptions
342
+ ├── TestingMiner → identifies framework, assertion style, mocking
343
+ ├── APIPatternMiner → finds response shapes, ORMs, route styles
344
+ └── GitPatternMiner → mines commit history, branches, co-change pairs
345
+
346
+
347
+ ConventionReport
348
+
349
+ ├── CONVENTIONS.md (default)
350
+ ├── AGENTS.md (--agents-md)
351
+ ├── CLAUDE.md (--claude-md, appends)
352
+ └── JSON (--json)
353
+ ```
354
+
355
+ All analysis is **100% local** — no API calls, no telemetry, no data leaves your machine.
356
+
357
+ ---
358
+
359
+ ## Performance
360
+
361
+ On a 1,000-file TypeScript monorepo:
362
+ - Without tree-sitter: ~0.8s
363
+ - With tree-sitter (full AST): ~2.1s
364
+
365
+ On a 500-file Python project:
366
+ - ~1.1s
367
+
368
+ Results are deterministic — same codebase always produces the same output.
369
+
370
+ ---
371
+
372
+ ## Contributing
373
+
374
+ ```bash
375
+ git clone https://github.com/yourusername/patchwork
376
+ cd patchwork
377
+ pip install -e '.[dev]'
378
+ pytest
379
+ ```
380
+
381
+ Pull requests welcome. See [CONTRIBUTING.md](CONTRIBUTING.md).
382
+
383
+ ---
384
+
385
+ ## License
386
+
387
+ MIT — free for personal and commercial use.
388
+
389
+ ---
390
+
391
+ ## Topics
392
+
393
+ `claude-code` · `agent-skills` · `mcp` · `context-engineering` · `hallucination-detection` · `code-conventions` · `static-analysis` · `tree-sitter` · `developer-tools` · `ai-coding`
@@ -0,0 +1,23 @@
1
+ patchwork/__init__.py,sha256=zFnPm2cWBIn2JDk87e6qu8nPtVip8lLOiZbC5fwoYZY,260
2
+ patchwork/cli.py,sha256=OwhdmXO6GaF98kWlAjz0cXWuj-eRt0SzANR-s9YC9xE,11473
3
+ patchwork/scanner.py,sha256=Tr-0Vjj04K-AVxYZrnS_S9o5bzdBHXjmtRi37yng8ts,5003
4
+ patchwork/mcp/__init__.py,sha256=eNowugtpL_Oy7r0klmZe8Ue0v-uQT6Z-qcp8hcqxWY0,14
5
+ patchwork/mcp/server.py,sha256=odT0hFhxEMc5h0jsDxvZ3SU-9cMnFzi4-BX6NRVEvy8,17697
6
+ patchwork/miners/__init__.py,sha256=Kpk8Cak7K8WzA6nNZfdfS8lJgMxPm3sf2NX2hWZyhOc,17
7
+ patchwork/miners/api_patterns.py,sha256=rbGv04sHM-KN9Sc207K5XG7OkxrDkbZ2hOycNucMbGA,7708
8
+ patchwork/miners/ast_base.py,sha256=gj3H8BZb-r3G89KRG3HmcXFq_j13Qu4DIBc5rDTgoM4,3603
9
+ patchwork/miners/config_detector.py,sha256=49Qu34CM0D1NOA5cpmhwLKOZ9y0VtIkm41mgDiGkG4g,8990
10
+ patchwork/miners/error_handling.py,sha256=NrDb-oViLIY1gxDMgldrHt9oDe0h7jbZfIp0q6v_ZmA,7171
11
+ patchwork/miners/git_patterns.py,sha256=Hs1OMLGv--9uCtiDH9YG3PP9qF2-INW_i734rCbecDA,5437
12
+ patchwork/miners/imports.py,sha256=NVzTDlLhRpkqvRLBcEZABVWWGQahR_3Ngeq4_rSOIbs,5858
13
+ patchwork/miners/naming.py,sha256=z3VkwC_cZaVACg4GkpTMC7BKUh2-PjcC38theqbz7Dw,11086
14
+ patchwork/miners/structure.py,sha256=w7LyyreYAGxuiDZcW-iZQA1fY5P8gyvIDcLPR4N38iw,6970
15
+ patchwork/miners/testing.py,sha256=Xi-9-FjGjtXdiaXEvDQVl25gHan_j_MZuW7NQEQdxGE,7346
16
+ patchwork/output/__init__.py,sha256=jJqTUADPphzvTRbB4QscOs3mSf-jIXyE1qIGjlRDWB0,17
17
+ patchwork/output/report.py,sha256=OwNyGMTluXb1HygJXSgLcIXz1YkUU8QEstiOlNpiO6o,16620
18
+ patchwork_conventions-0.1.0.dist-info/licenses/LICENSE,sha256=0Bzg8X3qKFT990jWkHnMN1zw70scmtM1P75TZ0zHF7s,1079
19
+ patchwork_conventions-0.1.0.dist-info/METADATA,sha256=2tuA67tmCFL_fg0mefPUv8MifnkHAm24t5hFWHSuJHc,11547
20
+ patchwork_conventions-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
21
+ patchwork_conventions-0.1.0.dist-info/entry_points.txt,sha256=mMBjspsdLQOId-R273l7aO22cU5O9UFaEQRJlfllkko,49
22
+ patchwork_conventions-0.1.0.dist-info/top_level.txt,sha256=aLF4R1vFf2HfqmKmZHlBkLny_-8Ye5nT-Pi8pKL2vE8,10
23
+ patchwork_conventions-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ patchwork = patchwork.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 patchwork contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ patchwork