一键导入
incremental-implementation
Comprehensive guide for implementing code incrementally following established patterns, conventions, and quality standards
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Comprehensive guide for implementing code incrementally following established patterns, conventions, and quality standards
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Plan before implementing - understand scope and approach with detailed guidance
Comprehensive checklist for documenting follow-up work and testing needs after implementation
Comprehensive systematic approach to achieving complete test coverage through structured category-based testing
Comprehensive guidelines for when and how to use mocks, stubs, and fakes in tests
| name | incremental-implementation |
| description | Comprehensive guide for implementing code incrementally following established patterns, conventions, and quality standards |
| languages | ["python","typescript","javascript","go","rust","java","csharp","php","ruby"] |
| subagents | ["code/feature","code/bug-fix","code/refactor"] |
| tools_needed | ["edit","write","read"] |
When implementing features or changes, follow this incremental, quality-focused approach:
Purpose: Maintain codebase consistency and avoid introducing technical debt.
How:
core-conventions.md (or equivalent project conventions) before startingWhy this matters:
Example:
# ✅ Good - follows Python conventions
def calculate_total_price(items: list[Item]) -> Decimal:
"""Calculate total price including tax."""
subtotal = sum(item.price for item in items)
return subtotal * Decimal("1.08") # 8% tax
# ❌ Bad - violates conventions
def calcTotalPrice(items): # camelCase (wrong for Python), no types
sub = 0 # unclear variable name
for i in items:
sub = sub + i.price # verbose when comprehension works
return sub * 1.08 # magic number, float instead of Decimal
Purpose: Keep similar code similar; don't introduce new patterns without reason.
How:
@router.get("/resource"), use thatcreated_at/updated_at, use thatWhy this matters:
Example:
If existing API routes look like this:
# Existing pattern in routes/user_routes.py
@router.get("/users/{user_id}")
async def get_user(
user_id: str,
user_service: UserService = Depends(get_user_service),
) -> UserResponse:
user = await user_service.get_by_id(user_id)
if not user:
raise HTTPException(status_code=404, detail="User not found")
return UserResponse.from_model(user)
Then new routes should match:
# ✅ Good - matches existing pattern
@router.get("/orders/{order_id}")
async def get_order(
order_id: str,
order_service: OrderService = Depends(get_order_service),
) -> OrderResponse:
order = await order_service.get_by_id(order_id)
if not order:
raise HTTPException(status_code=404, detail="Order not found")
return OrderResponse.from_model(order)
# ❌ Bad - introduces new pattern without justification
@router.route("/orders/<order_id>", methods=["GET"]) # Different decorator style
def get_order_sync(order_id): # Not async when others are
service = OrderService() # Direct instantiation, not dependency injection
result = service.find(order_id) # Different method name (find vs get_by_id)
return jsonify(result) # Different response pattern
Purpose: Explain the WHY, not the WHAT. Help future readers (including yourself) understand intent.
When to add comments:
When NOT to add comments:
Examples:
# ✅ Good comments (explain WHY)
# Use exponential backoff to avoid overwhelming the API during rate limit recovery
for attempt in range(max_retries):
delay = 2 ** attempt # 1s, 2s, 4s, 8s, 16s
await asyncio.sleep(delay)
# 86400 = seconds in a day (cache expires daily at midnight)
cache_ttl = 86400
# Intentionally not awaited - fire and forget analytics event
asyncio.create_task(track_user_action(user_id, "login"))
# WORKAROUND: API returns 200 with error in body instead of 4xx/5xx
# Remove this check when API v2 is deployed (see JIRA-1234)
if response.status == 200 and "error" in response.json():
raise APIError(response.json()["error"])
# ❌ Bad comments (restate code)
# Get user by ID
user = await user_service.get_by_id(user_id)
# Check if user is None
if user is None:
# Raise 404 error
raise HTTPException(status_code=404)
# Return user response
return UserResponse.from_model(user)
Purpose: Flag decisions that need user review or future attention.
When to add TODOs:
Format:
# TODO: [Category] Description (Owner, Date)
# TODO: Performance - Cache this query result (Alice, 2026-04-10)
# TODO: Security - Add rate limiting to this endpoint (Bob, 2026-04-10)
# TODO: Validation - Handle case where email is None (Charlie, 2026-04-10)
Categories:
TODO: Incomplete - Feature not fully implementedTODO: Bug - Known issue to fixTODO: Performance - Optimization neededTODO: Security - Security concernTODO: Refactor - Code quality improvementTODO: Validation - Missing input validationTODO: Testing - Missing test coverageTODO: Documentation - Missing docsExamples:
def process_payment(amount: Decimal, card_token: str) -> PaymentResult:
# TODO: Security - Add fraud detection check before processing (Alice, 2026-04-10)
# TODO: Performance - This calls payment API synchronously; make async (Bob, 2026-04-10)
result = payment_gateway.charge(amount, card_token)
# TODO: Incomplete - Handle gateway timeout (returns None currently) (Charlie, 2026-04-10)
if result is None:
return PaymentResult(status="failed", error="Gateway error")
return result
Purpose: Reduce context switching, make reviews easier, minimize merge conflicts.
How:
Why this matters:
Anti-pattern:
# ❌ Bad - jumping between files
1. Start implementing user_service.py
2. Realize you need UserRepository, switch to user_repository.py
3. Realize repository needs User model, switch to models.py
4. Go back to user_service.py, half-implement
5. Switch to user_routes.py to add API endpoint
6. Back to user_service.py to finish
Good pattern:
# ✅ Good - one file at a time
1. Implement models.py (User model) - COMPLETE
2. Implement user_repository.py (UserRepository) - COMPLETE
3. Implement user_service.py (UserService) - COMPLETE
4. Implement user_routes.py (API routes) - COMPLETE
5. Implement tests/test_user_service.py - COMPLETE
Problem: Introducing a new pattern when an existing one works.
Example:
# Existing pattern (constructor injection)
class UserService:
def __init__(self, repo: UserRepository):
self.repo = repo
# ❌ New code introduces different pattern (property injection)
class OrderService:
@property
def repo(self) -> OrderRepository:
return get_repository() # Global lookup instead of injection
Fix: Match the existing pattern (constructor injection).
Problem: Commenting what the code already says.
Example:
# ❌ Bad
# Loop through items
for item in items:
# Add item price to total
total += item.price
# ✅ Good (no comment needed - code is self-explanatory)
for item in items:
total += item.price
# ✅ Good (comment explains WHY, not WHAT)
# Sum prices excluding items marked as promotional (they're free)
for item in items:
if not item.is_promotional:
total += item.price
Problem: Jumping between files before completing any.
Why it's bad:
Fix: Finish one file completely before starting the next.
Problem: Writing code without understanding existing patterns.
Example:
Fix: Read 2-3 similar files before writing new code.
Problem: Writing vague TODOs that don't explain what needs to be done.
Bad:
# TODO: fix this
# TODO: improve
# TODO: check
Good:
# TODO: Performance - Cache this query result to avoid N+1 problem (Alice, 2026-04-10)
# TODO: Security - Add rate limiting to prevent brute force (Bob, 2026-04-10)
# TODO: Validation - Check that email is not already registered (Charlie, 2026-04-10)
Context: Adding OrderService to an existing codebase
Step 1: Read existing services
# Read 2-3 existing services to understand patterns
cat services/user_service.py
cat services/product_service.py
cat services/payment_service.py
Step 2: Match pattern
# ✅ Good - matches existing pattern
class OrderService:
"""Service for managing orders."""
def __init__(self, repo: OrderRepository):
"""Initialize with repository dependency."""
self.repo = repo
async def create_order(self, user_id: str, items: list[OrderItem]) -> Order:
"""Create new order for user.
Args:
user_id: ID of user placing order
items: List of items in order
Returns:
Created order
Raises:
ValidationError: If items list is empty
UserNotFoundError: If user doesn't exist
"""
if not items:
raise ValidationError("Order must have at least one item")
# TODO: Validation - Check that all items are in stock (Alice, 2026-04-10)
# Calculate total (excluding promotional items per business rules)
total = sum(item.price for item in items if not item.is_promotional)
order = Order(
user_id=user_id,
items=items,
total=total,
status=OrderStatus.PENDING,
)
return await self.repo.create(order)
Without comments (unclear intent):
def calculate_discount(price: Decimal, user: User) -> Decimal:
if user.created_at < datetime.now() - timedelta(days=365):
return price * Decimal("0.9")
return price
With good comments (intent is clear):
def calculate_discount(price: Decimal, user: User) -> Decimal:
"""Apply loyalty discount for long-term users.
Users who joined > 1 year ago get 10% discount as loyalty reward.
This is a business requirement from Product (see PRD-2024-Q3-05).
"""
one_year_ago = datetime.now() - timedelta(days=365)
if user.created_at < one_year_ago:
return price * Decimal("0.9") # 10% discount
return price
Key Principles:
Benefits:
Next Steps:
post-implementation-checklist skillfeature-planning skill