@juho0719/cckit 0.1.1
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/assets/agents/architect.md +211 -0
- package/assets/agents/build-error-resolver.md +114 -0
- package/assets/agents/ccwin-code-reviewer.md +224 -0
- package/assets/agents/database-reviewer.md +91 -0
- package/assets/agents/doc-updater.md +107 -0
- package/assets/agents/e2e-runner.md +107 -0
- package/assets/agents/planner.md +212 -0
- package/assets/agents/python-reviewer.md +98 -0
- package/assets/agents/refactor-cleaner.md +85 -0
- package/assets/agents/security-reviewer.md +108 -0
- package/assets/agents/superpower-code-reviewer.md +48 -0
- package/assets/agents/tdd-guide.md +80 -0
- package/assets/commands/build-fix.md +62 -0
- package/assets/commands/checkpoint.md +74 -0
- package/assets/commands/code-review.md +40 -0
- package/assets/commands/e2e.md +362 -0
- package/assets/commands/eval.md +120 -0
- package/assets/commands/orchestrate.md +172 -0
- package/assets/commands/plan.md +113 -0
- package/assets/commands/python-review.md +297 -0
- package/assets/commands/refactor-clean.md +80 -0
- package/assets/commands/sessions.md +305 -0
- package/assets/commands/tdd.md +326 -0
- package/assets/commands/test-coverage.md +69 -0
- package/assets/commands/update-codemaps.md +72 -0
- package/assets/commands/update-docs.md +84 -0
- package/assets/commands/verify.md +59 -0
- package/assets/hooks/post-edit-format.js +49 -0
- package/assets/hooks/post-edit-typecheck.js +96 -0
- package/assets/mcps/mcp-servers.json +92 -0
- package/assets/rules/common/agents.md +49 -0
- package/assets/rules/common/coding-style.md +48 -0
- package/assets/rules/common/git-workflow.md +45 -0
- package/assets/rules/common/hooks.md +30 -0
- package/assets/rules/common/patterns.md +31 -0
- package/assets/rules/common/performance.md +55 -0
- package/assets/rules/common/security.md +29 -0
- package/assets/rules/common/testing.md +29 -0
- package/assets/rules/python/coding-style.md +42 -0
- package/assets/rules/python/hooks.md +19 -0
- package/assets/rules/python/patterns.md +39 -0
- package/assets/rules/python/security.md +30 -0
- package/assets/rules/python/testing.md +38 -0
- package/assets/rules/typescript/coding-style.md +18 -0
- package/assets/rules/typescript/hooks.md +19 -0
- package/assets/rules/typescript/patterns.md +39 -0
- package/assets/rules/typescript/security.md +30 -0
- package/assets/rules/typescript/testing.md +38 -0
- package/assets/skills/api-design/SKILL.md +522 -0
- package/assets/skills/backend-patterns/SKILL.md +597 -0
- package/assets/skills/brainstorming/SKILL.md +96 -0
- package/assets/skills/coding-standards/SKILL.md +529 -0
- package/assets/skills/database-migrations/SKILL.md +334 -0
- package/assets/skills/deployment-patterns/SKILL.md +426 -0
- package/assets/skills/dispatching-parallel-agents/SKILL.md +180 -0
- package/assets/skills/docker-patterns/SKILL.md +363 -0
- package/assets/skills/e2e-testing/SKILL.md +325 -0
- package/assets/skills/eval-harness/SKILL.md +235 -0
- package/assets/skills/executing-plans/SKILL.md +84 -0
- package/assets/skills/finishing-a-development-branch/SKILL.md +200 -0
- package/assets/skills/frontend-patterns/SKILL.md +641 -0
- package/assets/skills/iterative-retrieval/SKILL.md +210 -0
- package/assets/skills/postgres-patterns/SKILL.md +145 -0
- package/assets/skills/python-patterns/SKILL.md +749 -0
- package/assets/skills/python-testing/SKILL.md +815 -0
- package/assets/skills/receiving-code-review/SKILL.md +213 -0
- package/assets/skills/requesting-code-review/SKILL.md +105 -0
- package/assets/skills/requesting-code-review/code-reviewer-template.md +146 -0
- package/assets/skills/subagent-driven-development/SKILL.md +242 -0
- package/assets/skills/subagent-driven-development/code-quality-reviewer-prompt.md +20 -0
- package/assets/skills/subagent-driven-development/implementer-prompt.md +78 -0
- package/assets/skills/subagent-driven-development/spec-reviewer-prompt.md +61 -0
- package/assets/skills/systematic-debugging/CREATION-LOG.md +114 -0
- package/assets/skills/systematic-debugging/SKILL.md +296 -0
- package/assets/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
- package/assets/skills/systematic-debugging/condition-based-waiting.md +115 -0
- package/assets/skills/systematic-debugging/defense-in-depth.md +122 -0
- package/assets/skills/systematic-debugging/root-cause-tracing.md +169 -0
- package/assets/skills/systematic-debugging/scripts/find-polluter.sh +63 -0
- package/assets/skills/systematic-debugging/test-academic.md +14 -0
- package/assets/skills/systematic-debugging/test-pressure-1.md +58 -0
- package/assets/skills/systematic-debugging/test-pressure-2.md +68 -0
- package/assets/skills/systematic-debugging/test-pressure-3.md +69 -0
- package/assets/skills/tdd-workflow/SKILL.md +409 -0
- package/assets/skills/test-driven-development/SKILL.md +371 -0
- package/assets/skills/test-driven-development/testing-anti-patterns.md +299 -0
- package/assets/skills/using-git-worktrees/SKILL.md +218 -0
- package/assets/skills/verification-before-completion/SKILL.md +139 -0
- package/assets/skills/verification-loop/SKILL.md +125 -0
- package/assets/skills/writing-plans/SKILL.md +116 -0
- package/dist/agents-AEKT67A6.js +9 -0
- package/dist/chunk-3GUKEMND.js +28 -0
- package/dist/chunk-3UNN3IBE.js +54 -0
- package/dist/chunk-3Y26YU4R.js +27 -0
- package/dist/chunk-5XOKKPAA.js +21 -0
- package/dist/chunk-6B46AIFM.js +136 -0
- package/dist/chunk-EYY2IZ7N.js +27 -0
- package/dist/chunk-K25UZZVG.js +17 -0
- package/dist/chunk-KEENFBLL.js +24 -0
- package/dist/chunk-RMUKD7CW.js +44 -0
- package/dist/chunk-W63UKEIT.js +50 -0
- package/dist/cli-VZRGF733.js +238 -0
- package/dist/commands-P5LILVZ5.js +9 -0
- package/dist/hooks-IIG2XK4I.js +9 -0
- package/dist/index.js +131 -0
- package/dist/mcps-67Q7TBGW.js +6 -0
- package/dist/paths-FT6KBIRD.js +10 -0
- package/dist/registry-EGXWYWWK.js +17 -0
- package/dist/rules-2CPBVNNJ.js +7 -0
- package/dist/skills-ULMW3UCM.js +8 -0
- package/package.json +36 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Restate requirements, assess risks, and create step-by-step implementation plan. WAIT for user CONFIRM before touching any code.
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Plan Command
|
|
6
|
+
|
|
7
|
+
This command invokes the **planner** agent to create a comprehensive implementation plan before writing any code.
|
|
8
|
+
|
|
9
|
+
## What This Command Does
|
|
10
|
+
|
|
11
|
+
1. **Restate Requirements** - Clarify what needs to be built
|
|
12
|
+
2. **Identify Risks** - Surface potential issues and blockers
|
|
13
|
+
3. **Create Step Plan** - Break down implementation into phases
|
|
14
|
+
4. **Wait for Confirmation** - MUST receive user approval before proceeding
|
|
15
|
+
|
|
16
|
+
## When to Use
|
|
17
|
+
|
|
18
|
+
Use `/plan` when:
|
|
19
|
+
- Starting a new feature
|
|
20
|
+
- Making significant architectural changes
|
|
21
|
+
- Working on complex refactoring
|
|
22
|
+
- Multiple files/components will be affected
|
|
23
|
+
- Requirements are unclear or ambiguous
|
|
24
|
+
|
|
25
|
+
## How It Works
|
|
26
|
+
|
|
27
|
+
The planner agent will:
|
|
28
|
+
|
|
29
|
+
1. **Analyze the request** and restate requirements in clear terms
|
|
30
|
+
2. **Break down into phases** with specific, actionable steps
|
|
31
|
+
3. **Identify dependencies** between components
|
|
32
|
+
4. **Assess risks** and potential blockers
|
|
33
|
+
5. **Estimate complexity** (High/Medium/Low)
|
|
34
|
+
6. **Present the plan** and WAIT for your explicit confirmation
|
|
35
|
+
|
|
36
|
+
## Example Usage
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
User: /plan I need to add real-time notifications when markets resolve
|
|
40
|
+
|
|
41
|
+
Agent (planner):
|
|
42
|
+
# Implementation Plan: Real-Time Market Resolution Notifications
|
|
43
|
+
|
|
44
|
+
## Requirements Restatement
|
|
45
|
+
- Send notifications to users when markets they're watching resolve
|
|
46
|
+
- Support multiple notification channels (in-app, email, webhook)
|
|
47
|
+
- Ensure notifications are delivered reliably
|
|
48
|
+
- Include market outcome and user's position result
|
|
49
|
+
|
|
50
|
+
## Implementation Phases
|
|
51
|
+
|
|
52
|
+
### Phase 1: Database Schema
|
|
53
|
+
- Add notifications table with columns: id, user_id, market_id, type, status, created_at
|
|
54
|
+
- Add user_notification_preferences table for channel preferences
|
|
55
|
+
- Create indexes on user_id and market_id for performance
|
|
56
|
+
|
|
57
|
+
### Phase 2: Notification Service
|
|
58
|
+
- Create notification service in lib/notifications.ts
|
|
59
|
+
- Implement notification queue using BullMQ/Redis
|
|
60
|
+
- Add retry logic for failed deliveries
|
|
61
|
+
- Create notification templates
|
|
62
|
+
|
|
63
|
+
### Phase 3: Integration Points
|
|
64
|
+
- Hook into market resolution logic (when status changes to "resolved")
|
|
65
|
+
- Query all users with positions in market
|
|
66
|
+
- Enqueue notifications for each user
|
|
67
|
+
|
|
68
|
+
### Phase 4: Frontend Components
|
|
69
|
+
- Create NotificationBell component in header
|
|
70
|
+
- Add NotificationList modal
|
|
71
|
+
- Implement real-time updates via Supabase subscriptions
|
|
72
|
+
- Add notification preferences page
|
|
73
|
+
|
|
74
|
+
## Dependencies
|
|
75
|
+
- Redis (for queue)
|
|
76
|
+
- Email service (SendGrid/Resend)
|
|
77
|
+
- Supabase real-time subscriptions
|
|
78
|
+
|
|
79
|
+
## Risks
|
|
80
|
+
- HIGH: Email deliverability (SPF/DKIM required)
|
|
81
|
+
- MEDIUM: Performance with 1000+ users per market
|
|
82
|
+
- MEDIUM: Notification spam if markets resolve frequently
|
|
83
|
+
- LOW: Real-time subscription overhead
|
|
84
|
+
|
|
85
|
+
## Estimated Complexity: MEDIUM
|
|
86
|
+
- Backend: 4-6 hours
|
|
87
|
+
- Frontend: 3-4 hours
|
|
88
|
+
- Testing: 2-3 hours
|
|
89
|
+
- Total: 9-13 hours
|
|
90
|
+
|
|
91
|
+
**WAITING FOR CONFIRMATION**: Proceed with this plan? (yes/no/modify)
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Important Notes
|
|
95
|
+
|
|
96
|
+
**CRITICAL**: The planner agent will **NOT** write any code until you explicitly confirm the plan with "yes" or "proceed" or similar affirmative response.
|
|
97
|
+
|
|
98
|
+
If you want changes, respond with:
|
|
99
|
+
- "modify: [your changes]"
|
|
100
|
+
- "different approach: [alternative]"
|
|
101
|
+
- "skip phase 2 and do phase 3 first"
|
|
102
|
+
|
|
103
|
+
## Integration with Other Commands
|
|
104
|
+
|
|
105
|
+
After planning:
|
|
106
|
+
- Use `/tdd` to implement with test-driven development
|
|
107
|
+
- Use `/build-fix` if build errors occur
|
|
108
|
+
- Use `/code-review` to review completed implementation
|
|
109
|
+
|
|
110
|
+
## Related Agents
|
|
111
|
+
|
|
112
|
+
This command invokes the `planner` agent located at:
|
|
113
|
+
`~/.claude/agents/planner.md`
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Comprehensive Python code review for PEP 8 compliance, type hints, security, and Pythonic idioms. Invokes the python-reviewer agent.
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Python Code Review
|
|
6
|
+
|
|
7
|
+
This command invokes the **python-reviewer** agent for comprehensive Python-specific code review.
|
|
8
|
+
|
|
9
|
+
## What This Command Does
|
|
10
|
+
|
|
11
|
+
1. **Identify Python Changes**: Find modified `.py` files via `git diff`
|
|
12
|
+
2. **Run Static Analysis**: Execute `ruff`, `mypy`, `pylint`, `black --check`
|
|
13
|
+
3. **Security Scan**: Check for SQL injection, command injection, unsafe deserialization
|
|
14
|
+
4. **Type Safety Review**: Analyze type hints and mypy errors
|
|
15
|
+
5. **Pythonic Code Check**: Verify code follows PEP 8 and Python best practices
|
|
16
|
+
6. **Generate Report**: Categorize issues by severity
|
|
17
|
+
|
|
18
|
+
## When to Use
|
|
19
|
+
|
|
20
|
+
Use `/python-review` when:
|
|
21
|
+
- After writing or modifying Python code
|
|
22
|
+
- Before committing Python changes
|
|
23
|
+
- Reviewing pull requests with Python code
|
|
24
|
+
- Onboarding to a new Python codebase
|
|
25
|
+
- Learning Pythonic patterns and idioms
|
|
26
|
+
|
|
27
|
+
## Review Categories
|
|
28
|
+
|
|
29
|
+
### CRITICAL (Must Fix)
|
|
30
|
+
- SQL/Command injection vulnerabilities
|
|
31
|
+
- Unsafe eval/exec usage
|
|
32
|
+
- Pickle unsafe deserialization
|
|
33
|
+
- Hardcoded credentials
|
|
34
|
+
- YAML unsafe load
|
|
35
|
+
- Bare except clauses hiding errors
|
|
36
|
+
|
|
37
|
+
### HIGH (Should Fix)
|
|
38
|
+
- Missing type hints on public functions
|
|
39
|
+
- Mutable default arguments
|
|
40
|
+
- Swallowing exceptions silently
|
|
41
|
+
- Not using context managers for resources
|
|
42
|
+
- C-style looping instead of comprehensions
|
|
43
|
+
- Using type() instead of isinstance()
|
|
44
|
+
- Race conditions without locks
|
|
45
|
+
|
|
46
|
+
### MEDIUM (Consider)
|
|
47
|
+
- PEP 8 formatting violations
|
|
48
|
+
- Missing docstrings on public functions
|
|
49
|
+
- Print statements instead of logging
|
|
50
|
+
- Inefficient string operations
|
|
51
|
+
- Magic numbers without named constants
|
|
52
|
+
- Not using f-strings for formatting
|
|
53
|
+
- Unnecessary list creation
|
|
54
|
+
|
|
55
|
+
## Automated Checks Run
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
# Type checking
|
|
59
|
+
mypy .
|
|
60
|
+
|
|
61
|
+
# Linting and formatting
|
|
62
|
+
ruff check .
|
|
63
|
+
black --check .
|
|
64
|
+
isort --check-only .
|
|
65
|
+
|
|
66
|
+
# Security scanning
|
|
67
|
+
bandit -r .
|
|
68
|
+
|
|
69
|
+
# Dependency audit
|
|
70
|
+
pip-audit
|
|
71
|
+
safety check
|
|
72
|
+
|
|
73
|
+
# Testing
|
|
74
|
+
pytest --cov=app --cov-report=term-missing
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Example Usage
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
User: /python-review
|
|
81
|
+
|
|
82
|
+
Agent:
|
|
83
|
+
# Python Code Review Report
|
|
84
|
+
|
|
85
|
+
## Files Reviewed
|
|
86
|
+
- app/routes/user.py (modified)
|
|
87
|
+
- app/services/auth.py (modified)
|
|
88
|
+
|
|
89
|
+
## Static Analysis Results
|
|
90
|
+
✓ ruff: No issues
|
|
91
|
+
✓ mypy: No errors
|
|
92
|
+
⚠️ black: 2 files need reformatting
|
|
93
|
+
✓ bandit: No security issues
|
|
94
|
+
|
|
95
|
+
## Issues Found
|
|
96
|
+
|
|
97
|
+
[CRITICAL] SQL Injection vulnerability
|
|
98
|
+
File: app/routes/user.py:42
|
|
99
|
+
Issue: User input directly interpolated into SQL query
|
|
100
|
+
```python
|
|
101
|
+
query = f"SELECT * FROM users WHERE id = {user_id}" # Bad
|
|
102
|
+
```
|
|
103
|
+
Fix: Use parameterized query
|
|
104
|
+
```python
|
|
105
|
+
query = "SELECT * FROM users WHERE id = %s" # Good
|
|
106
|
+
cursor.execute(query, (user_id,))
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
[HIGH] Mutable default argument
|
|
110
|
+
File: app/services/auth.py:18
|
|
111
|
+
Issue: Mutable default argument causes shared state
|
|
112
|
+
```python
|
|
113
|
+
def process_items(items=[]): # Bad
|
|
114
|
+
items.append("new")
|
|
115
|
+
return items
|
|
116
|
+
```
|
|
117
|
+
Fix: Use None as default
|
|
118
|
+
```python
|
|
119
|
+
def process_items(items=None): # Good
|
|
120
|
+
if items is None:
|
|
121
|
+
items = []
|
|
122
|
+
items.append("new")
|
|
123
|
+
return items
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
[MEDIUM] Missing type hints
|
|
127
|
+
File: app/services/auth.py:25
|
|
128
|
+
Issue: Public function without type annotations
|
|
129
|
+
```python
|
|
130
|
+
def get_user(user_id): # Bad
|
|
131
|
+
return db.find(user_id)
|
|
132
|
+
```
|
|
133
|
+
Fix: Add type hints
|
|
134
|
+
```python
|
|
135
|
+
def get_user(user_id: str) -> Optional[User]: # Good
|
|
136
|
+
return db.find(user_id)
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
[MEDIUM] Not using context manager
|
|
140
|
+
File: app/routes/user.py:55
|
|
141
|
+
Issue: File not closed on exception
|
|
142
|
+
```python
|
|
143
|
+
f = open("config.json") # Bad
|
|
144
|
+
data = f.read()
|
|
145
|
+
f.close()
|
|
146
|
+
```
|
|
147
|
+
Fix: Use context manager
|
|
148
|
+
```python
|
|
149
|
+
with open("config.json") as f: # Good
|
|
150
|
+
data = f.read()
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Summary
|
|
154
|
+
- CRITICAL: 1
|
|
155
|
+
- HIGH: 1
|
|
156
|
+
- MEDIUM: 2
|
|
157
|
+
|
|
158
|
+
Recommendation: ❌ Block merge until CRITICAL issue is fixed
|
|
159
|
+
|
|
160
|
+
## Formatting Required
|
|
161
|
+
Run: `black app/routes/user.py app/services/auth.py`
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Approval Criteria
|
|
165
|
+
|
|
166
|
+
| Status | Condition |
|
|
167
|
+
|--------|-----------|
|
|
168
|
+
| ✅ Approve | No CRITICAL or HIGH issues |
|
|
169
|
+
| ⚠️ Warning | Only MEDIUM issues (merge with caution) |
|
|
170
|
+
| ❌ Block | CRITICAL or HIGH issues found |
|
|
171
|
+
|
|
172
|
+
## Integration with Other Commands
|
|
173
|
+
|
|
174
|
+
- Use `/tdd` first to ensure tests pass
|
|
175
|
+
- Use `/code-review` for non-Python specific concerns
|
|
176
|
+
- Use `/python-review` before committing
|
|
177
|
+
- Use `/build-fix` if static analysis tools fail
|
|
178
|
+
|
|
179
|
+
## Framework-Specific Reviews
|
|
180
|
+
|
|
181
|
+
### Django Projects
|
|
182
|
+
The reviewer checks for:
|
|
183
|
+
- N+1 query issues (use `select_related` and `prefetch_related`)
|
|
184
|
+
- Missing migrations for model changes
|
|
185
|
+
- Raw SQL usage when ORM could work
|
|
186
|
+
- Missing `transaction.atomic()` for multi-step operations
|
|
187
|
+
|
|
188
|
+
### FastAPI Projects
|
|
189
|
+
The reviewer checks for:
|
|
190
|
+
- CORS misconfiguration
|
|
191
|
+
- Pydantic models for request validation
|
|
192
|
+
- Response models correctness
|
|
193
|
+
- Proper async/await usage
|
|
194
|
+
- Dependency injection patterns
|
|
195
|
+
|
|
196
|
+
### Flask Projects
|
|
197
|
+
The reviewer checks for:
|
|
198
|
+
- Context management (app context, request context)
|
|
199
|
+
- Proper error handling
|
|
200
|
+
- Blueprint organization
|
|
201
|
+
- Configuration management
|
|
202
|
+
|
|
203
|
+
## Related
|
|
204
|
+
|
|
205
|
+
- Agent: `agents/python-reviewer.md`
|
|
206
|
+
- Skills: `skills/python-patterns/`, `skills/python-testing/`
|
|
207
|
+
|
|
208
|
+
## Common Fixes
|
|
209
|
+
|
|
210
|
+
### Add Type Hints
|
|
211
|
+
```python
|
|
212
|
+
# Before
|
|
213
|
+
def calculate(x, y):
|
|
214
|
+
return x + y
|
|
215
|
+
|
|
216
|
+
# After
|
|
217
|
+
from typing import Union
|
|
218
|
+
|
|
219
|
+
def calculate(x: Union[int, float], y: Union[int, float]) -> Union[int, float]:
|
|
220
|
+
return x + y
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Use Context Managers
|
|
224
|
+
```python
|
|
225
|
+
# Before
|
|
226
|
+
f = open("file.txt")
|
|
227
|
+
data = f.read()
|
|
228
|
+
f.close()
|
|
229
|
+
|
|
230
|
+
# After
|
|
231
|
+
with open("file.txt") as f:
|
|
232
|
+
data = f.read()
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
### Use List Comprehensions
|
|
236
|
+
```python
|
|
237
|
+
# Before
|
|
238
|
+
result = []
|
|
239
|
+
for item in items:
|
|
240
|
+
if item.active:
|
|
241
|
+
result.append(item.name)
|
|
242
|
+
|
|
243
|
+
# After
|
|
244
|
+
result = [item.name for item in items if item.active]
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
### Fix Mutable Defaults
|
|
248
|
+
```python
|
|
249
|
+
# Before
|
|
250
|
+
def append(value, items=[]):
|
|
251
|
+
items.append(value)
|
|
252
|
+
return items
|
|
253
|
+
|
|
254
|
+
# After
|
|
255
|
+
def append(value, items=None):
|
|
256
|
+
if items is None:
|
|
257
|
+
items = []
|
|
258
|
+
items.append(value)
|
|
259
|
+
return items
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
### Use f-strings (Python 3.6+)
|
|
263
|
+
```python
|
|
264
|
+
# Before
|
|
265
|
+
name = "Alice"
|
|
266
|
+
greeting = "Hello, " + name + "!"
|
|
267
|
+
greeting2 = "Hello, {}".format(name)
|
|
268
|
+
|
|
269
|
+
# After
|
|
270
|
+
greeting = f"Hello, {name}!"
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
### Fix String Concatenation in Loops
|
|
274
|
+
```python
|
|
275
|
+
# Before
|
|
276
|
+
result = ""
|
|
277
|
+
for item in items:
|
|
278
|
+
result += str(item)
|
|
279
|
+
|
|
280
|
+
# After
|
|
281
|
+
result = "".join(str(item) for item in items)
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## Python Version Compatibility
|
|
285
|
+
|
|
286
|
+
The reviewer notes when code uses features from newer Python versions:
|
|
287
|
+
|
|
288
|
+
| Feature | Minimum Python |
|
|
289
|
+
|---------|----------------|
|
|
290
|
+
| Type hints | 3.5+ |
|
|
291
|
+
| f-strings | 3.6+ |
|
|
292
|
+
| Walrus operator (`:=`) | 3.8+ |
|
|
293
|
+
| Position-only parameters | 3.8+ |
|
|
294
|
+
| Match statements | 3.10+ |
|
|
295
|
+
| Type unions (`x | None`) | 3.10+ |
|
|
296
|
+
|
|
297
|
+
Ensure your project's `pyproject.toml` or `setup.py` specifies the correct minimum Python version.
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# Refactor Clean
|
|
2
|
+
|
|
3
|
+
Safely identify and remove dead code with test verification at every step.
|
|
4
|
+
|
|
5
|
+
## Step 1: Detect Dead Code
|
|
6
|
+
|
|
7
|
+
Run analysis tools based on project type:
|
|
8
|
+
|
|
9
|
+
| Tool | What It Finds | Command |
|
|
10
|
+
|------|--------------|---------|
|
|
11
|
+
| knip | Unused exports, files, dependencies | `npx knip` |
|
|
12
|
+
| depcheck | Unused npm dependencies | `npx depcheck` |
|
|
13
|
+
| ts-prune | Unused TypeScript exports | `npx ts-prune` |
|
|
14
|
+
| vulture | Unused Python code | `vulture src/` |
|
|
15
|
+
| deadcode | Unused Go code | `deadcode ./...` |
|
|
16
|
+
| cargo-udeps | Unused Rust dependencies | `cargo +nightly udeps` |
|
|
17
|
+
|
|
18
|
+
If no tool is available, use Grep to find exports with zero imports:
|
|
19
|
+
```
|
|
20
|
+
# Find exports, then check if they're imported anywhere
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Step 2: Categorize Findings
|
|
24
|
+
|
|
25
|
+
Sort findings into safety tiers:
|
|
26
|
+
|
|
27
|
+
| Tier | Examples | Action |
|
|
28
|
+
|------|----------|--------|
|
|
29
|
+
| **SAFE** | Unused utilities, test helpers, internal functions | Delete with confidence |
|
|
30
|
+
| **CAUTION** | Components, API routes, middleware | Verify no dynamic imports or external consumers |
|
|
31
|
+
| **DANGER** | Config files, entry points, type definitions | Investigate before touching |
|
|
32
|
+
|
|
33
|
+
## Step 3: Safe Deletion Loop
|
|
34
|
+
|
|
35
|
+
For each SAFE item:
|
|
36
|
+
|
|
37
|
+
1. **Run full test suite** — Establish baseline (all green)
|
|
38
|
+
2. **Delete the dead code** — Use Edit tool for surgical removal
|
|
39
|
+
3. **Re-run test suite** — Verify nothing broke
|
|
40
|
+
4. **If tests fail** — Immediately revert with `git checkout -- <file>` and skip this item
|
|
41
|
+
5. **If tests pass** — Move to next item
|
|
42
|
+
|
|
43
|
+
## Step 4: Handle CAUTION Items
|
|
44
|
+
|
|
45
|
+
Before deleting CAUTION items:
|
|
46
|
+
- Search for dynamic imports: `import()`, `require()`, `__import__`
|
|
47
|
+
- Search for string references: route names, component names in configs
|
|
48
|
+
- Check if exported from a public package API
|
|
49
|
+
- Verify no external consumers (check dependents if published)
|
|
50
|
+
|
|
51
|
+
## Step 5: Consolidate Duplicates
|
|
52
|
+
|
|
53
|
+
After removing dead code, look for:
|
|
54
|
+
- Near-duplicate functions (>80% similar) — merge into one
|
|
55
|
+
- Redundant type definitions — consolidate
|
|
56
|
+
- Wrapper functions that add no value — inline them
|
|
57
|
+
- Re-exports that serve no purpose — remove indirection
|
|
58
|
+
|
|
59
|
+
## Step 6: Summary
|
|
60
|
+
|
|
61
|
+
Report results:
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
Dead Code Cleanup
|
|
65
|
+
──────────────────────────────
|
|
66
|
+
Deleted: 12 unused functions
|
|
67
|
+
3 unused files
|
|
68
|
+
5 unused dependencies
|
|
69
|
+
Skipped: 2 items (tests failed)
|
|
70
|
+
Saved: ~450 lines removed
|
|
71
|
+
──────────────────────────────
|
|
72
|
+
All tests passing ✅
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## Rules
|
|
76
|
+
|
|
77
|
+
- **Never delete without running tests first**
|
|
78
|
+
- **One deletion at a time** — Atomic changes make rollback easy
|
|
79
|
+
- **Skip if uncertain** — Better to keep dead code than break production
|
|
80
|
+
- **Don't refactor while cleaning** — Separate concerns (clean first, refactor later)
|