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
- It removes duplication, applies SOLID principles, and simplifies any method that grew too complex during the Green phase.
- It validates inputs, checks for hardcoded secrets, scans dependencies for known vulnerabilities, and works through an explicit OWASP Top 10 checklist.
- It refactors in small steps, rerunning tests after each one instead of batching several refactors together.
- 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.
- 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.
- 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 - Reload VS Code, or open a new Copilot Chat; custom agents under
.github/agents/are picked up automatically. - 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
Accessibility Expert
Reviews code and designs against WCAG 2.1/2.2, covering semantics, keyboard and focus behavior, forms, media and dynamic SPA updates, and ships framework-specific examples plus a CI setup for automated checks.
Address Comments Agent
Works through pull request review comments one at a time: applies the minimal fix for each, pushes back on comments that don't make sense, adds test coverage, and commits with a descriptive message before moving to the next comment.
ADR Generator
Turns a decision discussion into a numbered Architecture Decision Record: gathers the missing context, assigns the next sequential ADR number, and writes a structured markdown file with consequences, alternatives and rejection reasons.