mirror of
https://github.com/wshobson/agents.git
synced 2026-03-18 09:37:15 +00:00
style: format all files with prettier
This commit is contained in:
@@ -11,12 +11,14 @@ Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD
|
||||
## Core Process
|
||||
|
||||
**1. Pre-Assessment**
|
||||
|
||||
- Run tests to establish green baseline
|
||||
- Analyze code smells and test coverage
|
||||
- Document current performance metrics
|
||||
- Create incremental refactoring plan
|
||||
|
||||
**2. Code Smell Detection**
|
||||
|
||||
- Duplicated code → Extract methods/classes
|
||||
- Long methods → Decompose into focused functions
|
||||
- Large classes → Split responsibilities
|
||||
@@ -27,6 +29,7 @@ Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD
|
||||
- Dead code → Remove
|
||||
|
||||
**3. Design Patterns**
|
||||
|
||||
- Apply Creational (Factory, Builder, Singleton)
|
||||
- Apply Structural (Adapter, Facade, Decorator)
|
||||
- Apply Behavioral (Strategy, Observer, Command)
|
||||
@@ -34,6 +37,7 @@ Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD
|
||||
- Use patterns only where they add clear value
|
||||
|
||||
**4. SOLID Principles**
|
||||
|
||||
- Single Responsibility: One reason to change
|
||||
- Open/Closed: Open for extension, closed for modification
|
||||
- Liskov Substitution: Subtypes substitutable
|
||||
@@ -41,6 +45,7 @@ Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD
|
||||
- Dependency Inversion: Depend on abstractions
|
||||
|
||||
**5. Refactoring Techniques**
|
||||
|
||||
- Extract Method/Variable/Interface
|
||||
- Inline unnecessary indirection
|
||||
- Rename for clarity
|
||||
@@ -51,6 +56,7 @@ Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD
|
||||
- Introduce Null Object
|
||||
|
||||
**6. Performance Optimization**
|
||||
|
||||
- Profile to identify bottlenecks
|
||||
- Optimize algorithms and data structures
|
||||
- Implement caching where beneficial
|
||||
@@ -59,6 +65,7 @@ Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD
|
||||
- Always measure before and after
|
||||
|
||||
**7. Incremental Steps**
|
||||
|
||||
- Make small, atomic changes
|
||||
- Run tests after each modification
|
||||
- Commit after each successful refactoring
|
||||
@@ -66,18 +73,21 @@ Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD
|
||||
- Use scaffolding when needed
|
||||
|
||||
**8. Architecture Evolution**
|
||||
|
||||
- Layer separation and dependency management
|
||||
- Module boundaries and interface definition
|
||||
- Event-driven patterns for decoupling
|
||||
- Database access pattern optimization
|
||||
|
||||
**9. Safety Verification**
|
||||
|
||||
- Run full test suite after each change
|
||||
- Performance regression testing
|
||||
- Mutation testing for test effectiveness
|
||||
- Rollback plan for major changes
|
||||
|
||||
**10. Advanced Patterns**
|
||||
|
||||
- Strangler Fig: Gradual legacy replacement
|
||||
- Branch by Abstraction: Large-scale changes
|
||||
- Parallel Change: Expand-contract pattern
|
||||
@@ -95,6 +105,7 @@ Prompt: "Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD
|
||||
## Safety Checklist
|
||||
|
||||
Before committing:
|
||||
|
||||
- ✓ All tests pass (100% green)
|
||||
- ✓ No functionality regression
|
||||
- ✓ Performance metrics acceptable
|
||||
@@ -104,6 +115,7 @@ Before committing:
|
||||
## Recovery Protocol
|
||||
|
||||
If tests fail:
|
||||
|
||||
- Immediately revert last change
|
||||
- Identify breaking refactoring
|
||||
- Apply smaller incremental changes
|
||||
@@ -112,6 +124,7 @@ If tests fail:
|
||||
## Example: Extract Method Pattern
|
||||
|
||||
**Before:**
|
||||
|
||||
```typescript
|
||||
class OrderProcessor {
|
||||
processOrder(order: Order): ProcessResult {
|
||||
@@ -125,7 +138,7 @@ class OrderProcessor {
|
||||
for (const item of order.items) {
|
||||
subtotal += item.price * item.quantity;
|
||||
}
|
||||
let total = subtotal + (subtotal * 0.08) + (subtotal > 100 ? 0 : 15);
|
||||
let total = subtotal + subtotal * 0.08 + (subtotal > 100 ? 0 : 15);
|
||||
|
||||
// Process payment...
|
||||
// Update inventory...
|
||||
@@ -135,6 +148,7 @@ class OrderProcessor {
|
||||
```
|
||||
|
||||
**After:**
|
||||
|
||||
```typescript
|
||||
class OrderProcessor {
|
||||
async processOrder(order: Order): Promise<ProcessResult> {
|
||||
@@ -142,10 +156,16 @@ class OrderProcessor {
|
||||
if (!validation.isValid) return ProcessResult.failure(validation.error);
|
||||
|
||||
const orderTotal = OrderTotal.calculate(order);
|
||||
const inventoryCheck = await this.inventoryService.checkAvailability(order.items);
|
||||
if (!inventoryCheck.available) return ProcessResult.failure(inventoryCheck.reason);
|
||||
const inventoryCheck = await this.inventoryService.checkAvailability(
|
||||
order.items,
|
||||
);
|
||||
if (!inventoryCheck.available)
|
||||
return ProcessResult.failure(inventoryCheck.reason);
|
||||
|
||||
await this.paymentService.processPayment(order.paymentMethod, orderTotal.total);
|
||||
await this.paymentService.processPayment(
|
||||
order.paymentMethod,
|
||||
orderTotal.total,
|
||||
);
|
||||
await this.inventoryService.reserveItems(order.items);
|
||||
await this.notificationService.sendOrderConfirmation(order, orderTotal);
|
||||
|
||||
@@ -153,8 +173,10 @@ class OrderProcessor {
|
||||
}
|
||||
|
||||
private validateOrder(order: Order): ValidationResult {
|
||||
if (!order.customerId) return ValidationResult.invalid("Customer ID required");
|
||||
if (order.items.length === 0) return ValidationResult.invalid("Order must contain items");
|
||||
if (!order.customerId)
|
||||
return ValidationResult.invalid("Customer ID required");
|
||||
if (order.items.length === 0)
|
||||
return ValidationResult.invalid("Order must contain items");
|
||||
return ValidationResult.valid();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user