tribunal-kit 1.0.0 → 2.4.2
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.
- package/.agent/.shared/ui-ux-pro-max/README.md +3 -3
- package/.agent/ARCHITECTURE.md +205 -10
- package/.agent/GEMINI.md +37 -7
- package/.agent/agents/accessibility-reviewer.md +134 -0
- package/.agent/agents/ai-code-reviewer.md +129 -0
- package/.agent/agents/frontend-specialist.md +3 -0
- package/.agent/agents/game-developer.md +21 -21
- package/.agent/agents/logic-reviewer.md +12 -0
- package/.agent/agents/mobile-reviewer.md +79 -0
- package/.agent/agents/orchestrator.md +56 -26
- package/.agent/agents/performance-reviewer.md +36 -0
- package/.agent/agents/supervisor-agent.md +156 -0
- package/.agent/agents/swarm-worker-contracts.md +166 -0
- package/.agent/agents/swarm-worker-registry.md +92 -0
- package/.agent/rules/GEMINI.md +134 -5
- package/.agent/scripts/bundle_analyzer.py +259 -0
- package/.agent/scripts/dependency_analyzer.py +247 -0
- package/.agent/scripts/lint_runner.py +188 -0
- package/.agent/scripts/patch_skills_meta.py +177 -0
- package/.agent/scripts/patch_skills_output.py +285 -0
- package/.agent/scripts/schema_validator.py +279 -0
- package/.agent/scripts/security_scan.py +224 -0
- package/.agent/scripts/session_manager.py +144 -3
- package/.agent/scripts/skill_integrator.py +234 -0
- package/.agent/scripts/strengthen_skills.py +220 -0
- package/.agent/scripts/swarm_dispatcher.py +317 -0
- package/.agent/scripts/test_runner.py +192 -0
- package/.agent/scripts/test_swarm_dispatcher.py +163 -0
- package/.agent/skills/agent-organizer/SKILL.md +132 -0
- package/.agent/skills/agentic-patterns/SKILL.md +335 -0
- package/.agent/skills/api-patterns/SKILL.md +226 -50
- package/.agent/skills/app-builder/SKILL.md +215 -52
- package/.agent/skills/architecture/SKILL.md +176 -31
- package/.agent/skills/bash-linux/SKILL.md +150 -134
- package/.agent/skills/behavioral-modes/SKILL.md +152 -160
- package/.agent/skills/brainstorming/SKILL.md +148 -101
- package/.agent/skills/brainstorming/dynamic-questioning.md +10 -0
- package/.agent/skills/clean-code/SKILL.md +139 -134
- package/.agent/skills/code-review-checklist/SKILL.md +177 -80
- package/.agent/skills/config-validator/SKILL.md +165 -0
- package/.agent/skills/csharp-developer/SKILL.md +107 -0
- package/.agent/skills/database-design/SKILL.md +252 -29
- package/.agent/skills/deployment-procedures/SKILL.md +122 -175
- package/.agent/skills/devops-engineer/SKILL.md +134 -0
- package/.agent/skills/devops-incident-responder/SKILL.md +98 -0
- package/.agent/skills/documentation-templates/SKILL.md +175 -121
- package/.agent/skills/dotnet-core-expert/SKILL.md +103 -0
- package/.agent/skills/edge-computing/SKILL.md +213 -0
- package/.agent/skills/frontend-design/SKILL.md +76 -0
- package/.agent/skills/frontend-design/color-system.md +18 -0
- package/.agent/skills/frontend-design/typography-system.md +18 -0
- package/.agent/skills/game-development/SKILL.md +69 -0
- package/.agent/skills/geo-fundamentals/SKILL.md +158 -99
- package/.agent/skills/github-operations/SKILL.md +354 -0
- package/.agent/skills/i18n-localization/SKILL.md +158 -96
- package/.agent/skills/intelligent-routing/SKILL.md +89 -285
- package/.agent/skills/intelligent-routing/router-manifest.md +65 -0
- package/.agent/skills/lint-and-validate/SKILL.md +229 -27
- package/.agent/skills/llm-engineering/SKILL.md +258 -0
- package/.agent/skills/local-first/SKILL.md +203 -0
- package/.agent/skills/mcp-builder/SKILL.md +159 -111
- package/.agent/skills/mobile-design/SKILL.md +102 -282
- package/.agent/skills/nextjs-react-expert/SKILL.md +143 -227
- package/.agent/skills/nodejs-best-practices/SKILL.md +201 -254
- package/.agent/skills/observability/SKILL.md +285 -0
- package/.agent/skills/parallel-agents/SKILL.md +124 -118
- package/.agent/skills/performance-profiling/SKILL.md +143 -89
- package/.agent/skills/plan-writing/SKILL.md +133 -97
- package/.agent/skills/platform-engineer/SKILL.md +135 -0
- package/.agent/skills/powershell-windows/SKILL.md +167 -104
- package/.agent/skills/python-patterns/SKILL.md +149 -361
- package/.agent/skills/python-pro/SKILL.md +114 -0
- package/.agent/skills/react-specialist/SKILL.md +107 -0
- package/.agent/skills/readme-builder/SKILL.md +270 -0
- package/.agent/skills/realtime-patterns/SKILL.md +296 -0
- package/.agent/skills/red-team-tactics/SKILL.md +136 -134
- package/.agent/skills/rust-pro/SKILL.md +237 -173
- package/.agent/skills/seo-fundamentals/SKILL.md +134 -82
- package/.agent/skills/server-management/SKILL.md +155 -104
- package/.agent/skills/sql-pro/SKILL.md +104 -0
- package/.agent/skills/systematic-debugging/SKILL.md +156 -79
- package/.agent/skills/tailwind-patterns/SKILL.md +163 -205
- package/.agent/skills/tdd-workflow/SKILL.md +148 -88
- package/.agent/skills/test-result-analyzer/SKILL.md +299 -0
- package/.agent/skills/testing-patterns/SKILL.md +141 -114
- package/.agent/skills/trend-researcher/SKILL.md +228 -0
- package/.agent/skills/ui-ux-pro-max/SKILL.md +107 -0
- package/.agent/skills/ui-ux-researcher/SKILL.md +234 -0
- package/.agent/skills/vue-expert/SKILL.md +118 -0
- package/.agent/skills/vulnerability-scanner/SKILL.md +228 -188
- package/.agent/skills/web-design-guidelines/SKILL.md +148 -33
- package/.agent/skills/webapp-testing/SKILL.md +171 -122
- package/.agent/skills/whimsy-injector/SKILL.md +349 -0
- package/.agent/skills/workflow-optimizer/SKILL.md +219 -0
- package/.agent/workflows/api-tester.md +279 -0
- package/.agent/workflows/audit.md +168 -0
- package/.agent/workflows/brainstorm.md +65 -19
- package/.agent/workflows/changelog.md +144 -0
- package/.agent/workflows/create.md +67 -14
- package/.agent/workflows/debug.md +122 -30
- package/.agent/workflows/deploy.md +82 -31
- package/.agent/workflows/enhance.md +59 -27
- package/.agent/workflows/fix.md +143 -0
- package/.agent/workflows/generate.md +84 -20
- package/.agent/workflows/migrate.md +163 -0
- package/.agent/workflows/orchestrate.md +66 -17
- package/.agent/workflows/performance-benchmarker.md +305 -0
- package/.agent/workflows/plan.md +76 -33
- package/.agent/workflows/preview.md +73 -17
- package/.agent/workflows/refactor.md +153 -0
- package/.agent/workflows/review-ai.md +140 -0
- package/.agent/workflows/review.md +83 -16
- package/.agent/workflows/session.md +154 -0
- package/.agent/workflows/status.md +74 -18
- package/.agent/workflows/strengthen-skills.md +99 -0
- package/.agent/workflows/swarm.md +194 -0
- package/.agent/workflows/test.md +80 -31
- package/.agent/workflows/tribunal-backend.md +55 -13
- package/.agent/workflows/tribunal-database.md +62 -18
- package/.agent/workflows/tribunal-frontend.md +58 -12
- package/.agent/workflows/tribunal-full.md +70 -11
- package/.agent/workflows/tribunal-mobile.md +123 -0
- package/.agent/workflows/tribunal-performance.md +152 -0
- package/.agent/workflows/ui-ux-pro-max.md +100 -82
- package/README.md +117 -62
- package/bin/tribunal-kit.js +542 -288
- package/package.json +10 -6
|
@@ -2,440 +2,228 @@
|
|
|
2
2
|
name: python-patterns
|
|
3
3
|
description: Python development principles and decision-making. Framework selection, async patterns, type hints, project structure. Teaches thinking, not copying.
|
|
4
4
|
allowed-tools: Read, Write, Edit, Glob, Grep
|
|
5
|
+
version: 1.0.0
|
|
6
|
+
last-updated: 2026-03-12
|
|
7
|
+
applies-to-model: gemini-2.5-pro, claude-3-7-sonnet
|
|
5
8
|
---
|
|
6
9
|
|
|
7
|
-
# Python
|
|
10
|
+
# Python Development Principles
|
|
8
11
|
|
|
9
|
-
> Python
|
|
10
|
-
>
|
|
12
|
+
> Python's flexibility is its greatest weakness.
|
|
13
|
+
> Without conventions, every project ends up with its own unpredictable shape.
|
|
11
14
|
|
|
12
15
|
---
|
|
13
16
|
|
|
14
|
-
##
|
|
17
|
+
## Framework Selection
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
| Use Case | Recommended | When to Use |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| REST API, general-purpose | FastAPI | Type-safe, async, auto-docs via OpenAPI |
|
|
22
|
+
| REST API, batteries-included | Django + DRF | Rapid development, ORM included, admin panel |
|
|
23
|
+
| Microservice / minimal API | Flask | Simple, no overhead, full control |
|
|
24
|
+
| Data pipeline / ETL | No framework | Standard library + pandas/polars as needed |
|
|
25
|
+
| CLI tool | Click or Typer | Better than argparse for complex CLIs |
|
|
26
|
+
| Async task queue | Celery + Redis | Background jobs, scheduled tasks |
|
|
17
27
|
|
|
18
|
-
-
|
|
19
|
-
- Choose async vs sync based on CONTEXT
|
|
20
|
-
- Don't default to same framework every time
|
|
28
|
+
**Decision question:** Does this need an ORM, admin panel, and auth out of the box? → Django. Does it need type-safe inputs with automatic validation? → FastAPI. Is it small and needs nothing? → Flask.
|
|
21
29
|
|
|
22
30
|
---
|
|
23
31
|
|
|
24
|
-
##
|
|
32
|
+
## Type Hints (Required on All New Code)
|
|
25
33
|
|
|
26
|
-
|
|
34
|
+
Python type hints are not optional — they are documentation that also enables static analysis.
|
|
27
35
|
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
│ └── FastAPI (async, modern, fast)
|
|
33
|
-
│
|
|
34
|
-
├── Full-stack web / CMS / Admin
|
|
35
|
-
│ └── Django (batteries-included)
|
|
36
|
-
│
|
|
37
|
-
├── Simple / Script / Learning
|
|
38
|
-
│ └── Flask (minimal, flexible)
|
|
39
|
-
│
|
|
40
|
-
├── AI/ML API serving
|
|
41
|
-
│ └── FastAPI (Pydantic, async, uvicorn)
|
|
42
|
-
│
|
|
43
|
-
└── Background workers
|
|
44
|
-
└── Celery + any framework
|
|
45
|
-
```
|
|
36
|
+
```python
|
|
37
|
+
# ❌ No type hints
|
|
38
|
+
def create_user(email, role):
|
|
39
|
+
...
|
|
46
40
|
|
|
47
|
-
|
|
41
|
+
# ✅ Typed
|
|
42
|
+
from typing import Literal
|
|
48
43
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
| **Async** | Native | Django 5.0+ | Via extensions |
|
|
53
|
-
| **Admin** | Manual | Built-in | Via extensions |
|
|
54
|
-
| **ORM** | Choose your own | Django ORM | Choose your own |
|
|
55
|
-
| **Learning curve** | Low | Medium | Low |
|
|
44
|
+
def create_user(email: str, role: Literal["admin", "user"] = "user") -> dict[str, str]:
|
|
45
|
+
...
|
|
46
|
+
```
|
|
56
47
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
4. Existing infrastructure?
|
|
48
|
+
**Rules:**
|
|
49
|
+
- All function parameters and return values must be typed
|
|
50
|
+
- Use `from __future__ import annotations` for forward references
|
|
51
|
+
- Run `mypy` or `pyright` as part of CI — type errors fail the build
|
|
62
52
|
|
|
63
53
|
---
|
|
64
54
|
|
|
65
|
-
##
|
|
66
|
-
|
|
67
|
-
### When to Use Async
|
|
55
|
+
## Project Structure
|
|
68
56
|
|
|
69
57
|
```
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
def (sync) is better when:
|
|
78
|
-
├── CPU-bound operations
|
|
79
|
-
├── Simple scripts
|
|
80
|
-
├── Legacy codebase
|
|
81
|
-
├── Team unfamiliar with async
|
|
82
|
-
└── Blocking libraries (no async version)
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### The Golden Rule
|
|
58
|
+
src/
|
|
59
|
+
api/ Route definitions (thin — parse and delegate)
|
|
60
|
+
services/ Business logic (no HTTP awareness)
|
|
61
|
+
repositories/ Database access (no business logic)
|
|
62
|
+
models/ Pydantic models + SQLAlchemy models
|
|
63
|
+
lib/ Shared utilities
|
|
64
|
+
config.py Settings via pydantic-settings
|
|
86
65
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
66
|
+
tests/
|
|
67
|
+
unit/ Isolated function tests
|
|
68
|
+
integration/ Database and external service tests
|
|
90
69
|
|
|
91
|
-
|
|
92
|
-
├── Mix sync and async carelessly
|
|
93
|
-
├── Use sync libraries in async code
|
|
94
|
-
└── Force async for CPU work
|
|
70
|
+
pyproject.toml — single source of truth for deps, linting, test config
|
|
95
71
|
```
|
|
96
72
|
|
|
97
|
-
### Async Library Selection
|
|
98
|
-
|
|
99
|
-
| Need | Async Library |
|
|
100
|
-
|------|---------------|
|
|
101
|
-
| HTTP client | httpx |
|
|
102
|
-
| PostgreSQL | asyncpg |
|
|
103
|
-
| Redis | aioredis / redis-py async |
|
|
104
|
-
| File I/O | aiofiles |
|
|
105
|
-
| Database ORM | SQLAlchemy 2.0 async, Tortoise |
|
|
106
|
-
|
|
107
73
|
---
|
|
108
74
|
|
|
109
|
-
##
|
|
75
|
+
## Async Patterns
|
|
110
76
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
```
|
|
114
|
-
Always type:
|
|
115
|
-
├── Function parameters
|
|
116
|
-
├── Return types
|
|
117
|
-
├── Class attributes
|
|
118
|
-
├── Public APIs
|
|
119
|
-
|
|
120
|
-
Can skip:
|
|
121
|
-
├── Local variables (let inference work)
|
|
122
|
-
├── One-off scripts
|
|
123
|
-
├── Tests (usually)
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### Common Type Patterns
|
|
77
|
+
FastAPI uses async by default. Know when to use it and when not to.
|
|
127
78
|
|
|
128
79
|
```python
|
|
129
|
-
#
|
|
80
|
+
# ✅ Use async for I/O-bound operations
|
|
81
|
+
@app.get("/users/{user_id}")
|
|
82
|
+
async def get_user(user_id: str, db: AsyncSession = Depends(get_db)):
|
|
83
|
+
return await user_service.find_by_id(db, user_id)
|
|
130
84
|
|
|
131
|
-
#
|
|
132
|
-
|
|
133
|
-
|
|
85
|
+
# ✅ Use sync for CPU-bound operations (or offload to thread pool)
|
|
86
|
+
import asyncio
|
|
87
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
134
88
|
|
|
135
|
-
|
|
136
|
-
def process(data: str | dict) -> None: ...
|
|
89
|
+
executor = ThreadPoolExecutor()
|
|
137
90
|
|
|
138
|
-
|
|
139
|
-
def
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
from typing import Callable
|
|
144
|
-
def apply(fn: Callable[[int], str]) -> str: ...
|
|
91
|
+
@app.post("/process")
|
|
92
|
+
async def process_image(file: UploadFile):
|
|
93
|
+
loop = asyncio.get_event_loop()
|
|
94
|
+
result = await loop.run_in_executor(executor, cpu_intensive_work, file)
|
|
95
|
+
return result
|
|
145
96
|
```
|
|
146
97
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
```
|
|
150
|
-
When to use Pydantic:
|
|
151
|
-
├── API request/response models
|
|
152
|
-
├── Configuration/settings
|
|
153
|
-
├── Data validation
|
|
154
|
-
├── Serialization
|
|
155
|
-
|
|
156
|
-
Benefits:
|
|
157
|
-
├── Runtime validation
|
|
158
|
-
├── Auto-generated JSON schema
|
|
159
|
-
├── Works with FastAPI natively
|
|
160
|
-
└── Clear error messages
|
|
161
|
-
```
|
|
98
|
+
**Never:** `time.sleep()` inside an async function — use `await asyncio.sleep()` instead.
|
|
162
99
|
|
|
163
100
|
---
|
|
164
101
|
|
|
165
|
-
##
|
|
166
|
-
|
|
167
|
-
### Structure Selection
|
|
168
|
-
|
|
169
|
-
```
|
|
170
|
-
Small project / Script:
|
|
171
|
-
├── main.py
|
|
172
|
-
├── utils.py
|
|
173
|
-
└── requirements.txt
|
|
174
|
-
|
|
175
|
-
Medium API:
|
|
176
|
-
├── app/
|
|
177
|
-
│ ├── __init__.py
|
|
178
|
-
│ ├── main.py
|
|
179
|
-
│ ├── models/
|
|
180
|
-
│ ├── routes/
|
|
181
|
-
│ ├── services/
|
|
182
|
-
│ └── schemas/
|
|
183
|
-
├── tests/
|
|
184
|
-
└── pyproject.toml
|
|
185
|
-
|
|
186
|
-
Large application:
|
|
187
|
-
├── src/
|
|
188
|
-
│ └── myapp/
|
|
189
|
-
│ ├── core/
|
|
190
|
-
│ ├── api/
|
|
191
|
-
│ ├── services/
|
|
192
|
-
│ ├── models/
|
|
193
|
-
│ └── ...
|
|
194
|
-
├── tests/
|
|
195
|
-
└── pyproject.toml
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### FastAPI Structure Principles
|
|
199
|
-
|
|
200
|
-
```
|
|
201
|
-
Organize by feature or layer:
|
|
202
|
-
|
|
203
|
-
By layer:
|
|
204
|
-
├── routes/ (API endpoints)
|
|
205
|
-
├── services/ (business logic)
|
|
206
|
-
├── models/ (database models)
|
|
207
|
-
├── schemas/ (Pydantic models)
|
|
208
|
-
└── dependencies/ (shared deps)
|
|
209
|
-
|
|
210
|
-
By feature:
|
|
211
|
-
├── users/
|
|
212
|
-
│ ├── routes.py
|
|
213
|
-
│ ├── service.py
|
|
214
|
-
│ └── schemas.py
|
|
215
|
-
└── products/
|
|
216
|
-
└── ...
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
---
|
|
220
|
-
|
|
221
|
-
## 5. Django Principles (2025)
|
|
222
|
-
|
|
223
|
-
### Django Async (Django 5.0+)
|
|
224
|
-
|
|
225
|
-
```
|
|
226
|
-
Django supports async:
|
|
227
|
-
├── Async views
|
|
228
|
-
├── Async middleware
|
|
229
|
-
├── Async ORM (limited)
|
|
230
|
-
└── ASGI deployment
|
|
231
|
-
|
|
232
|
-
When to use async in Django:
|
|
233
|
-
├── External API calls
|
|
234
|
-
├── WebSocket (Channels)
|
|
235
|
-
├── High-concurrency views
|
|
236
|
-
└── Background task triggering
|
|
237
|
-
```
|
|
102
|
+
## Error Handling
|
|
238
103
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
104
|
+
```python
|
|
105
|
+
# Custom exception hierarchy
|
|
106
|
+
class AppError(Exception):
|
|
107
|
+
def __init__(self, message: str, code: str, status_code: int = 400):
|
|
108
|
+
self.message = message
|
|
109
|
+
self.code = code
|
|
110
|
+
self.status_code = status_code
|
|
111
|
+
super().__init__(message)
|
|
112
|
+
|
|
113
|
+
class NotFoundError(AppError):
|
|
114
|
+
def __init__(self, resource: str, id: str):
|
|
115
|
+
super().__init__(f"{resource} {id} not found", "NOT_FOUND", 404)
|
|
116
|
+
|
|
117
|
+
class ValidationError(AppError):
|
|
118
|
+
def __init__(self, message: str):
|
|
119
|
+
super().__init__(message, "VALIDATION_FAILED", 400)
|
|
120
|
+
|
|
121
|
+
# FastAPI exception handler
|
|
122
|
+
@app.exception_handler(AppError)
|
|
123
|
+
async def app_error_handler(request: Request, exc: AppError):
|
|
124
|
+
return JSONResponse(
|
|
125
|
+
status_code=exc.status_code,
|
|
126
|
+
content={"error": exc.message, "code": exc.code}
|
|
127
|
+
)
|
|
257
128
|
```
|
|
258
129
|
|
|
259
130
|
---
|
|
260
131
|
|
|
261
|
-
##
|
|
132
|
+
## Dependency Management
|
|
262
133
|
|
|
263
|
-
|
|
134
|
+
Use `pyproject.toml` with `uv` or `poetry`:
|
|
264
135
|
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
└── Want to handle concurrency
|
|
271
|
-
|
|
272
|
-
Use def when:
|
|
273
|
-
├── Blocking operations
|
|
274
|
-
├── Sync database drivers
|
|
275
|
-
├── CPU-bound work
|
|
276
|
-
└── FastAPI runs in threadpool automatically
|
|
277
|
-
```
|
|
136
|
+
```toml
|
|
137
|
+
[project]
|
|
138
|
+
name = "my-service"
|
|
139
|
+
version = "0.1.0"
|
|
140
|
+
requires-python = ">=3.11"
|
|
278
141
|
|
|
279
|
-
|
|
142
|
+
dependencies = [
|
|
143
|
+
"fastapi>=0.110",
|
|
144
|
+
"pydantic>=2.0",
|
|
145
|
+
"sqlalchemy[asyncio]>=2.0",
|
|
146
|
+
"asyncpg>=0.29",
|
|
147
|
+
]
|
|
280
148
|
|
|
149
|
+
[project.optional-dependencies]
|
|
150
|
+
dev = [
|
|
151
|
+
"pytest>=7.0",
|
|
152
|
+
"pytest-asyncio>=0.23",
|
|
153
|
+
"mypy>=1.0",
|
|
154
|
+
"ruff>=0.3",
|
|
155
|
+
]
|
|
281
156
|
```
|
|
282
|
-
Use dependencies for:
|
|
283
|
-
├── Database sessions
|
|
284
|
-
├── Current user / Auth
|
|
285
|
-
├── Configuration
|
|
286
|
-
├── Shared resources
|
|
287
|
-
|
|
288
|
-
Benefits:
|
|
289
|
-
├── Testability (mock dependencies)
|
|
290
|
-
├── Clean separation
|
|
291
|
-
├── Automatic cleanup (yield)
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
### Pydantic v2 Integration
|
|
295
157
|
|
|
296
|
-
|
|
297
|
-
# FastAPI + Pydantic are tightly integrated:
|
|
298
|
-
|
|
299
|
-
# Request validation
|
|
300
|
-
@app.post("/users")
|
|
301
|
-
async def create(user: UserCreate) -> UserResponse:
|
|
302
|
-
# user is already validated
|
|
303
|
-
...
|
|
304
|
-
|
|
305
|
-
# Response serialization
|
|
306
|
-
# Return type becomes response schema
|
|
307
|
-
```
|
|
158
|
+
**Never use `requirements.txt` for production projects** — no lock file, no version bounds, no dev/prod separation.
|
|
308
159
|
|
|
309
160
|
---
|
|
310
161
|
|
|
311
|
-
##
|
|
162
|
+
## Code Quality Tools
|
|
312
163
|
|
|
313
|
-
|
|
164
|
+
```bash
|
|
165
|
+
# Linting + formatting (replaces black + flake8 + isort)
|
|
166
|
+
ruff check . --fix
|
|
167
|
+
ruff format .
|
|
314
168
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
| **BackgroundTasks** | Simple, in-process tasks |
|
|
318
|
-
| **Celery** | Distributed, complex workflows |
|
|
319
|
-
| **ARQ** | Async, Redis-based |
|
|
320
|
-
| **RQ** | Simple Redis queue |
|
|
321
|
-
| **Dramatiq** | Actor-based, simpler than Celery |
|
|
169
|
+
# Type checking
|
|
170
|
+
mypy src/
|
|
322
171
|
|
|
323
|
-
|
|
172
|
+
# Testing
|
|
173
|
+
pytest tests/ -v --tb=short
|
|
324
174
|
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
├── Quick operations
|
|
328
|
-
├── No persistence needed
|
|
329
|
-
├── Fire-and-forget
|
|
330
|
-
└── Same process
|
|
331
|
-
|
|
332
|
-
Celery/ARQ:
|
|
333
|
-
├── Long-running tasks
|
|
334
|
-
├── Need retry logic
|
|
335
|
-
├── Distributed workers
|
|
336
|
-
├── Persistent queue
|
|
337
|
-
└── Complex workflows
|
|
175
|
+
# Pre-commit (runs all of the above)
|
|
176
|
+
pre-commit run --all-files
|
|
338
177
|
```
|
|
339
178
|
|
|
179
|
+
Configure all tools in `pyproject.toml` — not `.flake8`, `.mypy.ini`, and `.ruff.toml` separately.
|
|
180
|
+
|
|
340
181
|
---
|
|
341
182
|
|
|
342
|
-
##
|
|
183
|
+
## Output Format
|
|
343
184
|
|
|
344
|
-
|
|
185
|
+
When this skill produces or reviews code, structure your output as follows:
|
|
345
186
|
|
|
346
187
|
```
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
188
|
+
━━━ Python Patterns Report ━━━━━━━━━━━━━━━━━━━━━━━━
|
|
189
|
+
Skill: Python Patterns
|
|
190
|
+
Language: [detected language / framework]
|
|
191
|
+
Scope: [N files · N functions]
|
|
192
|
+
─────────────────────────────────────────────────
|
|
193
|
+
✅ Passed: [checks that passed, or "All clean"]
|
|
194
|
+
⚠️ Warnings: [non-blocking issues, or "None"]
|
|
195
|
+
❌ Blocked: [blocking issues requiring fix, or "None"]
|
|
196
|
+
─────────────────────────────────────────────────
|
|
197
|
+
VBC status: PENDING → VERIFIED
|
|
198
|
+
Evidence: [test output / lint pass / compile success]
|
|
357
199
|
```
|
|
358
200
|
|
|
359
|
-
|
|
201
|
+
**VBC (Verification-Before-Completion) is mandatory.**
|
|
202
|
+
Do not mark status as VERIFIED until concrete terminal evidence is provided.
|
|
360
203
|
|
|
361
|
-
```
|
|
362
|
-
Include:
|
|
363
|
-
├── Error code (programmatic)
|
|
364
|
-
├── Message (human readable)
|
|
365
|
-
├── Details (field-level when applicable)
|
|
366
|
-
└── NOT stack traces (security)
|
|
367
|
-
```
|
|
368
204
|
|
|
369
205
|
---
|
|
370
206
|
|
|
371
|
-
##
|
|
372
|
-
|
|
373
|
-
### Testing Strategy
|
|
207
|
+
## 🏛️ Tribunal Integration (Anti-Hallucination)
|
|
374
208
|
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
| **Unit** | Business logic | pytest |
|
|
378
|
-
| **Integration** | API endpoints | pytest + httpx/TestClient |
|
|
379
|
-
| **E2E** | Full workflows | pytest + DB |
|
|
209
|
+
**Slash command: `/tribunal-backend`**
|
|
210
|
+
**Active reviewers: `logic` · `security` · `dependency` · `type-safety`**
|
|
380
211
|
|
|
381
|
-
###
|
|
212
|
+
### ❌ Forbidden AI Tropes in Python
|
|
382
213
|
|
|
383
|
-
|
|
384
|
-
|
|
214
|
+
1. **Missing Type Hints** — writing `def func(a, b):` instead of fully typing parameters and return values.
|
|
215
|
+
2. **Bare `except:` blocks** — catching all exceptions blindly without logging or raising `AppError`.
|
|
216
|
+
3. **`requirements.txt` over `pyproject.toml`** — hallucinating outdated dependency management practices.
|
|
217
|
+
4. **Blocking the async event loop** — writing synchronous I/O or `time.sleep()` inside an `async def` FastAPI route.
|
|
218
|
+
5. **Assuming Django for microservices** — defaulting to a massive framework when `FastAPI` or `Flask` fits better.
|
|
385
219
|
|
|
386
|
-
|
|
387
|
-
from httpx import AsyncClient
|
|
220
|
+
### ✅ Pre-Flight Self-Audit
|
|
388
221
|
|
|
389
|
-
|
|
390
|
-
async def test_endpoint():
|
|
391
|
-
async with AsyncClient(app=app, base_url="http://test") as client:
|
|
392
|
-
response = await client.get("/users")
|
|
393
|
-
assert response.status_code == 200
|
|
222
|
+
Review these questions before generating Python code:
|
|
394
223
|
```
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
224
|
+
✅ Are all function parameters and return types strictly typed?
|
|
225
|
+
✅ Did I use the modern toolchain (`uv`/`poetry`, `ruff`, `mypy`)?
|
|
226
|
+
✅ Did I accidentally block the async event loop with sync code?
|
|
227
|
+
✅ Are domain errors properly caught and mapped to HTTP status codes without leaking stack traces?
|
|
228
|
+
✅ Is my dependency selection precise and explicitly declared in `pyproject.toml`?
|
|
398
229
|
```
|
|
399
|
-
Common fixtures:
|
|
400
|
-
├── db_session → Database connection
|
|
401
|
-
├── client → Test client
|
|
402
|
-
├── authenticated_user → User with token
|
|
403
|
-
└── sample_data → Test data setup
|
|
404
|
-
```
|
|
405
|
-
|
|
406
|
-
---
|
|
407
|
-
|
|
408
|
-
## 10. Decision Checklist
|
|
409
|
-
|
|
410
|
-
Before implementing:
|
|
411
|
-
|
|
412
|
-
- [ ] **Asked user about framework preference?**
|
|
413
|
-
- [ ] **Chosen framework for THIS context?** (not just default)
|
|
414
|
-
- [ ] **Decided async vs sync?**
|
|
415
|
-
- [ ] **Planned type hint strategy?**
|
|
416
|
-
- [ ] **Defined project structure?**
|
|
417
|
-
- [ ] **Planned error handling?**
|
|
418
|
-
- [ ] **Considered background tasks?**
|
|
419
|
-
|
|
420
|
-
---
|
|
421
|
-
|
|
422
|
-
## 11. Anti-Patterns to Avoid
|
|
423
|
-
|
|
424
|
-
### ❌ DON'T:
|
|
425
|
-
- Default to Django for simple APIs (FastAPI may be better)
|
|
426
|
-
- Use sync libraries in async code
|
|
427
|
-
- Skip type hints for public APIs
|
|
428
|
-
- Put business logic in routes/views
|
|
429
|
-
- Ignore N+1 queries
|
|
430
|
-
- Mix async and sync carelessly
|
|
431
|
-
|
|
432
|
-
### ✅ DO:
|
|
433
|
-
- Choose framework based on context
|
|
434
|
-
- Ask about async requirements
|
|
435
|
-
- Use Pydantic for validation
|
|
436
|
-
- Separate concerns (routes → services → repos)
|
|
437
|
-
- Test critical paths
|
|
438
|
-
|
|
439
|
-
---
|
|
440
|
-
|
|
441
|
-
> **Remember**: Python patterns are about decision-making for YOUR specific context. Don't copy code—think about what serves your application best.
|