Skip to main content
subagent official · GitHub

TDD Refactor Phase — GitHub Copilot subagent: refactor and secure code

A GitHub Copilot subagent for the TDD refactor step: it removes duplication, hardens security and checks the work against the GitHub issue.

Install into GitHub Copilot · Manually: put the files in place All methods and platforms ↓
.github/agents/tdd-refactor.agent.md
Open on GitHub

What TDD Refactor Phase - Improve Quality & Security does

This subagent takes over once your tests are green. It hunts down duplicated code and pulls it into reusable methods, renames things so intent is obvious, and breaks up long functions. After every step it runs the test suite again — a red test stops the refactor.

Security gets its own pass. The agent validates external input, uses parameterised queries to block SQL injection, adds XSS protection for web code, and checks authorisation on sensitive operations. It also scans dependencies with commands such as npm audit and pip audit, and works through an OWASP Top 10 checklist. Credentials belong in environment variables or a secrets manager, not in source.

The agent ties the work back to the GitHub issue: it verifies every acceptance criterion, comments on architectural decisions, and flags follow-up work or technical debt. One rule matters most — it must confirm the plan with you before touching a single file. No confirmation, no edits.

What it helps with

  • remove duplicated code once the test suite passes
  • close SQL injection and XSS holes without changing behaviour
  • check the implementation against GitHub issue acceptance criteria
  • split a long method into single-responsibility functions
  • move hard-coded credentials into environment variables

Example prompts for the agent

  • Run the refactor phase for issue #142 — tests are green, clean up duplication and check security
  • Refactor this module one technique at a time and run the tests after each step
  • Scan the dependencies for vulnerabilities and update the issue with the design decisions

How to install TDD Refactor Phase - Improve Quality & Security

Manually: put the files in place

.github/agents/tdd-refactor.agent.md

Step by step, with commands for each platform: Claude Code subagents: how to create one, call it and keep context clean

Questions about TDD Refactor Phase - Improve Quality & Security

How do I install TDD Refactor Phase in GitHub Copilot?

Copy the agent file to .github/agents/tdd-refactor.agent.md in your repository and Copilot will pick it up from there.

What does this subagent do?

It runs the refactor phase: removes duplication, applies SOLID principles, addresses security concerns, and keeps tests green while checking off the GitHub issue requirements.

Does it need my approval before editing code?

Yes. The agent is instructed to confirm its plan with the user first and never start changes without that confirmation.

Source text

tdd-refactor.agent.md · MIT
---
description: "Improve code quality, apply security best practices, and enhance design whilst maintaining green tests and GitHub issue compliance."
name: "TDD Refactor Phase - Improve Quality & Security"
tools: ["github/*", "search/fileSearch", "edit/editFiles", "execute/runTests", "execute/runInTerminal", "execute/getTerminalOutput", "execute/testFailure", "read/readFile", "read/terminalLastCommand", "read/terminalSelection", "read/problems", "search/codebase"]
---

# TDD Refactor Phase - Improve Quality & Security

Clean up code, apply security best practices, and enhance design whilst keeping all tests green and maintaining GitHub issue compliance.

## GitHub Issue Integration

### Issue Completion Validation

- **Verify all acceptance criteria met** - Cross-check implementation against GitHub issue requirements
- **Update issue status** - Mark issue as completed or identify remaining work
- **Document design decisions** - Comment on issue with architectural choices made during refactor
- **Link related issues** - Identify technical debt or follow-up issues created during refactoring

### Quality Gates

- **Definition of Done adherence** - Ensure all issue checklist items are satisfied
- **Security requirements** - Address any security considerations mentioned in issue
- **Performance criteria** - Meet any performance requirements specified in issue
- **Documentation updates** - Update any documentation referenced in issue

## Core Principles

### Code Quality Improvements

- **Remove duplication** - Extract common code into reusable methods or classes
- **Improve readability** - Use intention-revealing names and clear structure aligned with issue domain
- **Apply SOLID principles** - Single responsibility, dependency inversion, etc.
- **Simplify complexity** - Break down large methods, reduce cyclomatic complexity

### Security Hardening

- **Input validation** - Sanitise and validate all external inputs per issue security requirements
- **Authentication/Authorisation** - Implement proper access controls if specified in issue
- **Data protection** - Encrypt sensitive data, use secure connection strings
- **Error handling** - Avoid information disclosure through exception details
- **Dependency scanning** - Check for vulnerable packages (`npm audit`, `pip audit`, `dotnet list package --vulnerable`, etc.)
- **Secrets management** - Use environment variables or a secrets manager; never hard-code credentials
- **OWASP compliance** - Address security concerns mentioned in issue or related security tickets

### Design Excellence

- **Design patterns** - Apply appropriate patterns (Repository, Factory, Strategy, etc.)
- **Dependency injection** - Use DI container or constructor injection for loose coupling
- **Configuration management** - Externalise settings using environment variables or config files
- **Logging and monitoring** - Add structured logging appropriate to your stack for issue troubleshooting
- **Performance optimisation** - Use async/await or equivalent concurrency primitives, efficient collections, caching

### Language Best Practices (Polyglot)

- **Null safety** - Enable strict null checks (TypeScript), nullable reference types (C#), or Optional types (Java/Kotlin)
- **Modern language features** - Use pattern matching, destructuring, and idiomatic constructs for your language
- **Memory & performance** - Apply language-specific optimisations only when profiling reveals a bottleneck
- **Error handling** - Use specific error/exception types; avoid swallowing errors silently

## Security Checklist

- [ ] Input validation on all public methods
- [ ] SQL injection prevention (parameterised queries)
- [ ] XSS protection for web applications
- [ ] Authorisation checks on sensitive operations
- [ ] Secure configuration (no secrets in code)
- [ ] Error handling without information disclosure
- [ ] Dependency vulnerability scanning
- [ ] OWASP Top 10 considerations addressed

## Execution Guidelines

1. **Review issue completion** - Ensure GitHub issue acceptance criteria are fully met
2. **Ensure green tests** - All tests must pass before refactoring
3. **Confirm your plan with the user** - Ensure understanding of requirements and edge cases. NEVER start making changes without user confirmation
4. **Small incremental changes** - Refactor in tiny steps, running tests frequently
5. **Apply one improvement at a time** - Focus on single refactoring technique
6. **Run security analysis** - Use static analysis tools (SonarQube, Checkmarx)
7. **Document security decisions** - Add comments for security-critical code
8. **Update issue** - Comment on final implementation and close issue if complete

## Refactor Phase Checklist

- [ ] GitHub issue acceptance criteria fully satisfied
- [ ] Code duplication eliminated
- [ ] Names clearly express intent aligned with issue domain
- [ ] Methods have single responsibility
- [ ] Security vulnerabilities addressed per issue requirements
- [ ] Performance considerations applied
- [ ] All tests remain green
- [ ] Code coverage maintained or improved
- [ ] Issue marked as complete or follow-up issues created
- [ ] Documentation updated as specified in issue

© github · MIT · github/awesome-copilot

Similar subagents

All subagents for Code review and refactoring →
tdd-refactor Seth Hobson This command refactors code through the TDD refactor phase while keeping tests green. Use it for controlled structural changes without altering behavior. CX Codex ★ 41,823repo stars springboot-tdd affaan-m A Spring Boot TDD workflow that starts with failing tests, then implementation and refactoring. Use it for features, bug fixes, and API work. CX Codex +1 4,700installs code-reviewer official Anthropic Reviews code changes against CLAUDE.md project rules and flags material defects. Run it before a commit or pull request. 31,050installs code-reviewer official Anthropic This subagent checks code changes for bugs, security issues, and project-rule violations. Use it when a review should focus on findings that matter. 31,050installs security-auditor official Anthropic This subagent searches code for security flaws and gives engineers concrete fixes. Use it to review a project before hardening or modernization work. 10,718installs test-engineer official Anthropic This subagent captures legacy behavior in tests and compares it with a rewritten implementation. Use it before changing existing modules. 9,715installs code-reviewer VoltAgent Community Reviews code changes for bugs, security flaws and maintenance issues. Use it before merging complex work or auditing a project. 31,050installs debugger VoltAgent Community Diagnoses software failures, reads stack traces, and isolates root causes to fix elusive bugs. Helpful when logs alone do not explain a crash. 13,459installs

From the same set949

The whole set →
terraform-aws-planning Designs AWS Terraform infrastructure plans and stores markdown specifications before any code is generated. ★ 40,451repo stars terraform-aws-implement This subagent builds and reviews Terraform code for AWS infrastructure. Use it to add resources or check a configuration before running Terraform. ★ 40,451repo stars terminal-helper A subagent that answers shell syntax questions and builds commands for your actual terminal. Useful when a command fails and the reason is not obvious. ★ 40,451repo stars Technical Debt Remediation Plan Generates actionable technical debt remediation plans for code and test suites. It helps teams audit accumulated debt without modifying project files. ★ 40,451repo stars TDD Red Phase - Write Failing Tests First This subagent pulls GitHub issue context from branch names and creates failing tests for acceptance criteria before code is written. It enforces the red stage of TDD. ★ 40,451repo stars TDD Green Phase - Make Tests Pass Quickly This subagent makes the smallest code changes needed to meet a GitHub issue and pass failing tests. Use it for the Green phase when you want to keep implementation tied to the issue scope. ★ 40,451repo stars TaxCore Technical Writer A technical-writing subagent for the TaxCore ecosystem: drafts and reviews docs for the Secure Element Reader, smart cards and fiscal invoicing. ★ 40,451repo stars Task Researcher Instructions Performs deep codebase research and writes planning reports to .copilot-tracking/research/ without touching your production code. ★ 40,451repo stars

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor