[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill-300c806b-9f9b-4773-b5e8-bcaad96766b2":3,"$f4dU9HjJRZPMmnDhTv25Hizu7P_egWnh4ghrb1fY5I90":43},{"id":4,"title":5,"description":6,"categoryId":7,"moduleId":8,"tags":9,"prompt":10,"icon":11,"source":12,"sourceUrl":13,"authorId":14,"authorName":15,"isPublic":16,"stars":17,"runs":18,"createdAt":19,"updatedAt":19,"module":20,"category":27,"packages":34},"300c806b-9f9b-4773-b5e8-bcaad96766b2","tdd-workflows-tdd-refactor","使用时与TDD工作流程和TDD重构一起使用","cat_coding_review","mod_coding","sickn33,coding","---\nname: tdd-workflows-tdd-refactor\ndescription: \"Use when working with tdd workflows tdd refactor\"\nrisk: unknown\nsource: community\ndate_added: \"2026-02-27\"\n---\n\n## Use this skill when\n\n- Working on tdd workflows tdd refactor tasks or workflows\n- Needing guidance, best practices, or checklists for tdd workflows tdd refactor\n\n## Do not use this skill when\n\n- The task is unrelated to tdd workflows tdd refactor\n- You need a different domain or tool outside this scope\n\n## Instructions\n\n- Clarify goals, constraints, and required inputs.\n- Apply relevant best practices and validate outcomes.\n- Provide actionable steps and verification.\n- If detailed examples are required, open `resources\u002Fimplementation-playbook.md`.\n\nRefactor code with confidence using comprehensive test safety net:\n\n[Extended thinking: This tool uses the tdd-orchestrator agent (opus model) for sophisticated refactoring while maintaining all tests green. It applies design patterns, improves code quality, and optimizes performance with the safety of comprehensive test coverage.]\n\n## Usage\n\nUse Task tool with subagent_type=\"tdd-orchestrator\" to perform safe refactoring.\n\nPrompt: \"Refactor this code while keeping all tests green: $ARGUMENTS. Apply TDD refactor phase:\n\n## Core Process\n\n**1. Pre-Assessment**\n- Run tests to establish green baseline\n- Analyze code smells and test coverage\n- Document current performance metrics\n- Create incremental refactoring plan\n\n**2. Code Smell Detection**\n- Duplicated code → Extract methods\u002Fclasses\n- Long methods → Decompose into focused functions\n- Large classes → Split responsibilities\n- Long parameter lists → Parameter objects\n- Feature Envy → Move methods to appropriate classes\n- Primitive Obsession → Value objects\n- Switch statements → Polymorphism\n- Dead code → Remove\n\n**3. Design Patterns**\n- Apply Creational (Factory, Builder, Singleton)\n- Apply Structural (Adapter, Facade, Decorator)\n- Apply Behavioral (Strategy, Observer, Command)\n- Apply Domain (Repository, Service, Value Objects)\n- Use patterns only where they add clear value\n\n**4. SOLID Principles**\n- Single Responsibility: One reason to change\n- Open\u002FClosed: Open for extension, closed for modification\n- Liskov Substitution: Subtypes substitutable\n- Interface Segregation: Small, focused interfaces\n- Dependency Inversion: Depend on abstractions\n\n**5. Refactoring Techniques**\n- Extract Method\u002FVariable\u002FInterface\n- Inline unnecessary indirection\n- Rename for clarity\n- Move Method\u002FField to appropriate classes\n- Replace Magic Numbers with constants\n- Encapsulate fields\n- Replace Conditional with Polymorphism\n- Introduce Null Object\n\n**6. Performance Optimization**\n- Profile to identify bottlenecks\n- Optimize algorithms and data structures\n- Implement caching where beneficial\n- Reduce database queries (N+1 elimination)\n- Lazy loading and pagination\n- Always measure before and after\n\n**7. Incremental Steps**\n- Make small, atomic changes\n- Run tests after each modification\n- Commit after each successful refactoring\n- Keep refactoring separate from behavior changes\n- Use scaffolding when needed\n\n**8. Architecture Evolution**\n- Layer separation and dependency management\n- Module boundaries and interface definition\n- Event-driven patterns for decoupling\n- Database access pattern optimization\n\n**9. Safety Verification**\n- Run full test suite after each change\n- Performance regression testing\n- Mutation testing for test effectiveness\n- Rollback plan for major changes\n\n**10. Advanced Patterns**\n- Strangler Fig: Gradual legacy replacement\n- Branch by Abstraction: Large-scale changes\n- Parallel Change: Expand-contract pattern\n- Mikado Method: Dependency graph navigation\n\n## Output Requirements\n\n- Refactored code with improvements applied\n- Test results (all green)\n- Before\u002Fafter metrics comparison\n- Applied refactoring techniques list\n- Performance improvement measurements\n- Remaining technical debt assessment\n\n## Safety Checklist\n\nBefore committing:\n- ✓ All tests pass (100% green)\n- ✓ No functionality regression\n- ✓ Performance metrics acceptable\n- ✓ Code coverage maintained\u002Fimproved\n- ✓ Documentation updated\n\n## Recovery Protocol\n\nIf tests fail:\n- Immediately revert last change\n- Identify breaking refactoring\n- Apply smaller incremental changes\n- Use version control for safe experimentation\n\n## Example: Extract Method Pattern\n\n**Before:**\n```typescript\nclass OrderProcessor {\n  processOrder(order: Order): ProcessResult {\n    \u002F\u002F Validation\n    if (!order.customerId || order.items.length === 0) {\n      return { success: false, error: \"Invalid order\" };\n    }\n\n    \u002F\u002F Calculate totals\n    let subtotal = 0;\n    for (const item of order.items) {\n      subtotal += item.price * item.quantity;\n    }\n    let total = subtotal + (subtotal * 0.08) + (subtotal > 100 ? 0 : 15);\n\n    \u002F\u002F Process payment...\n    \u002F\u002F Update inventory...\n    \u002F\u002F Send confirmation...\n  }\n}\n```\n\n**After:**\n```typescript\nclass OrderProcessor {\n  async processOrder(order: Order): Promise\u003CProcessResult> {\n    const validation = this.validateOrder(order);\n    if (!validation.isValid) return ProcessResult.failure(validation.error);\n\n    const orderTotal = OrderTotal.calculate(order);\n    const inventoryCheck = await this.inventoryService.checkAvailability(order.items);\n    if (!inventoryCheck.available) return ProcessResult.failure(inventoryCheck.reason);\n\n    await this.paymentService.processPayment(order.paymentMethod, orderTotal.total);\n    await this.inventoryService.reserveItems(order.items);\n    await this.notificationService.sendOrderConfirmation(order, orderTotal);\n\n    return ProcessResult.success(order.id, orderTotal.total);\n  }\n\n  private validateOrder(order: Order): ValidationResult {\n    if (!order.customerId) return ValidationResult.invalid(\"Customer ID required\");\n    if (order.items.length === 0) return ValidationResult.invalid(\"Order must contain items\");\n    return ValidationResult.valid();\n  }\n}\n```\n\n**Applied:** Extract Method, Value Objects, Dependency Injection, Async patterns\n\nCode to refactor: $ARGUMENTS\"\n\n## Limitations\n- Use this skill only when the task clearly matches the scope described above.\n- Do not treat the output as a substitute for environment-specific validation, testing, or expert review.\n- Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.\n","","imported","https:\u002F\u002Fgithub.com\u002Fsickn33\u002Fantigravity-awesome-skills","user_system_seed","SkillOPIC",true,209,154,"2026-05-16 13:43:19",{"id":8,"name":21,"slug":22,"icon":23,"description":24,"sort":25,"createdAt":26},"编程开发","coding","mdi-code-braces","代码生成、调试、审查，提升开发效率",2,"2026-05-16 12:53:40",{"id":7,"name":28,"slug":29,"icon":30,"description":31,"moduleId":8,"sort":32,"skillCount":33,"createdAt":26},"代码审查","review","mdi-magnify-scan","代码质量分析、安全审查",4,145,[35],{"id":36,"skillId":4,"version":37,"fileName":38,"fileSize":39,"filePath":40,"fileHash":41,"manifest":42,"createdAt":19},"1321cd76-f3b9-49d7-ad20-f9296d43a060","1.0.0","tdd-workflows-tdd-refactor.zip",2901,"uploads\u002Fskills\u002F300c806b-9f9b-4773-b5e8-bcaad96766b2\u002Ftdd-workflows-tdd-refactor.zip","1b5c90f6f2b788917b645dd99df1f9f50727e39323e7a41dc82d15d800fce4b5","[{\"path\":\"SKILL.md\",\"isDirectory\":false,\"size\":6381}]",{"code":44,"message":45,"data":46},200,"success",{"items":47,"stats":48,"page":51},[],{"averageRating":49,"totalRatings":49,"ratingCounts":50},0,[49,49,49,49,49],{"limit":52,"offset":49,"hasMore":53,"nextOffset":52,"ratedOnly":16},15,false]