~/ai_assets_directory_
Copilot Agent verified · tested by us 38.7k stars · whole github/awesome-copilot repo
tdd-refactor.agent.md

TDD Refactor Phase Agent

Third stage of the TDD workflow: cleans up duplication and design, and hardens security (input validation, secrets, OWASP) while keeping every test green.

Overview

The closing stage of the TDD trio, run after TDD Green once the tests are passing. It cleans up the quick-and-dirty implementation and adds a security pass, all while keeping the test suite green throughout.

How it works

  1. It removes duplication, applies SOLID principles, and simplifies any method that grew too complex during the Green phase.
  2. It validates inputs, checks for hardcoded secrets, scans dependencies for known vulnerabilities, and works through an explicit OWASP Top 10 checklist.
  3. It refactors in small steps, rerunning tests after each one instead of batching several refactors together.
  4. It cross-checks the implementation against the GitHub issue's acceptance criteria, and either closes the issue or opens follow-up issues for anything left over.
  5. Every refactor step must leave the test suite passing; a broken test blocks moving to the next step.

Examples

"Refactor the email-validation code now that the test is green, and
check it against the OWASP checklist."

Installation

You need VS Code with the GitHub Copilot extension. Consider installing TDD Red and TDD Green alongside it, they're meant to be used together.

  1. Create the agents folder and download the file into your repo:
    mkdir -p .github/agents
    curl -o .github/agents/tdd-refactor.agent.md \
      https://raw.githubusercontent.com/github/awesome-copilot/main/agents/tdd-refactor.agent.md
    
  2. Reload VS Code, or open a new Copilot Chat; custom agents under .github/agents/ are picked up automatically.
  3. Pick this agent from the mode picker in Copilot Chat once your tests are green, and confirm it keeps them passing after each cleanup step.

Related assets