version: 1
kind: context
name: Code Refactoring
description: A context for improving code structure, readability, and maintainability without changing external behavior.

context:
  personas:
    - personas/martin-fowler.yaml
    - personas/uncle-bob.yaml
  rules:
    - rules/the-must-follow.yaml
  mcps:
    - mcps/sequential-thinking.yaml
    - mcps/context7.yaml
    - mcps/web-search.yaml
    - mcps/github-api.yaml
  actions:
    - actions/refactor.yaml
prompt: |
  Let's improve the health of our codebase.
  Refactoring is key to long-term maintainability and scalability.
  We will identify code smells and apply proven patterns to fix them.
  Our approach will be disciplined and safe, backed by a solid test suite.
  Let's begin by analyzing the code and identifying areas for improvement.
enhanced-prompt: |-
  # Code Refactoring Context

  ## Core Philosophy
  Refactoring improves code structure without altering external behavior. We focus on small, safe, and incremental changes to enhance readability, reduce complexity, and increase maintainability.

  ## Key Principles
  1.  **Preserve Functionality**: All external behavior must remain unchanged.
  2.  **Test First**: Ensure comprehensive test coverage before starting.
  3.  **Incremental Changes**: Apply small, verifiable refactorings one at a time.
  4.  **Address Code Smells**: Systematically identify and fix issues like duplicated code, long methods, and large classes.

  ## Common Refactoring Patterns
  - **Extract Method**: Turn a code fragment into its own method.
  - **Extract Class**: Move a group of related fields and methods to a new class.
  - **Rename Variable/Method**: Use clear and descriptive names.
  - **Simplify Conditional**: Replace complex conditional logic with simpler, more expressive code.
  - **Replace Magic Numbers with Constants**: Improve readability and maintainability.

  ## Refactoring Process
  1.  **Analyze**: Identify code smells and areas for improvement.
  2.  **Plan**: Define refactoring goals and ensure test coverage.
  3.  **Execute**: Apply refactoring patterns incrementally.
  4.  **Verify**: Run tests after each change to ensure correctness.
  5.  **Commit**: Commit small, atomic changes with clear messages.

  ## Success Criteria
  - ✅ All existing tests pass.
  - ✅ Code quality metrics (e.g., complexity, duplication) are improved.
  - ✅ Readability and maintainability are demonstrably better.
  - ✅ No performance degradation.

  **Ready to refactor. What part of the codebase should we improve first?**
