Refactoring
Purpose
Improve internal code structure without unintentionally changing externally observable behavior.
Project Stack
TypeScript, React, Python, FastAPI, SQLAlchemy.
Operating Principles
- Understand behavior before changing structure.
- Keep refactors separate from unrelated feature work.
- Prefer small reversible changes.
- Preserve public contracts unless change is explicitly intended.
- Use tests and type checks as safety nets.
- Remove duplication only when the abstraction is clear.
- Do not create abstractions merely to reduce line count.
- Preserve error behavior unless intentionally changing it.
- Compare the final diff carefully.
Required Workflow
- Establish current behavior.
- Identify the structural problem.
- Define the desired structure.
- Refactor incrementally.
- Run checks after meaningful steps.
- Compare behavior before and after.
- Review the final diff for accidental changes.
Evidence Rules
Use the strongest available evidence in this order:
- Runtime behavior
- Automated test results
- Type checking, linting, and build results
- Installed package/source behavior
- Official framework or library documentation
- Repository configuration
- Static code inspection
- General model knowledge
Never report an assumption as a verified result.
Tool Selection
- Use Filesystem MCP for repository exploration and file inspection.
- Use Context7 for current, version-specific library/framework documentation.
- Use Fetch when official documentation or public web resources need to be retrieved.
- Use Playwright for browser behavior, frontend interaction, forms, authentication flows, and UI verification.
- Use GitHub CLI for repository, branch, pull request, issue, workflow, and CI operations.
- Prefer the smallest tool set that establishes reliable evidence.
Failure Handling
When something fails:
- Reproduce the failure.
- Capture the exact error.
- Identify the failing layer.
- Check whether the failure is environmental, dependency-related, configuration-related, or caused by application code.
- Research uncertain behavior using authoritative sources.
- Apply the smallest appropriate fix.
- Reproduce the original failure again.
- Run regression checks.
- Inspect the final diff.
Do not hide failures by weakening tests, suppressing errors, deleting evidence, or claiming success without verification.
Security
- Never expose secrets.
- Never commit credentials.
- Treat all external input as untrusted.
- Preserve authentication and authorization boundaries.
- Avoid leaking internal implementation details through errors.
- Review security implications whenever the skill touches users, data, credentials, networking, or deployment.
Completion Criteria
A task using this skill is complete only when:
- The requested behavior is implemented.
- Existing project conventions are preserved.
- Relevant static checks pass.
- Relevant tests pass or their absence is explicitly reported.
- Browser verification is performed when the task affects user-facing behavior.
- Security implications have been considered.
- The final diff has been inspected.
- Verified facts are clearly distinguished from assumptions or remaining uncertainty.
1---2name: refactoring3description: Refactoring4---5# Refactoring67## Purpose89Improve internal code structure without unintentionally changing externally observable behavior.1011## Project Stack1213TypeScript, React, Python, FastAPI, SQLAlchemy.1415## Operating Principles16171. Understand behavior before changing structure.182. Keep refactors separate from unrelated feature work.193. Prefer small reversible changes.204. Preserve public contracts unless change is explicitly intended.215. Use tests and type checks as safety nets.226. Remove duplication only when the abstraction is clear.237. Do not create abstractions merely to reduce line count.248. Preserve error behavior unless intentionally changing it.259. Compare the final diff carefully.2627## Required Workflow28291. Establish current behavior.302. Identify the structural problem.313. Define the desired structure.324. Refactor incrementally.335. Run checks after meaningful steps.346. Compare behavior before and after.357. Review the final diff for accidental changes.3637## Evidence Rules3839Use the strongest available evidence in this order:40411. Runtime behavior422. Automated test results433. Type checking, linting, and build results444. Installed package/source behavior455. Official framework or library documentation466. Repository configuration477. Static code inspection488. General model knowledge4950Never report an assumption as a verified result.5152## Tool Selection5354- Use Filesystem MCP for repository exploration and file inspection.55- Use Context7 for current, version-specific library/framework documentation.56- Use Fetch when official documentation or public web resources need to be retrieved.57- Use Playwright for browser behavior, frontend interaction, forms, authentication flows, and UI verification.58- Use GitHub CLI for repository, branch, pull request, issue, workflow, and CI operations.59- Prefer the smallest tool set that establishes reliable evidence.6061## Failure Handling6263When something fails:64651. Reproduce the failure.662. Capture the exact error.673. Identify the failing layer.684. Check whether the failure is environmental, dependency-related, configuration-related, or caused by application code.695. Research uncertain behavior using authoritative sources.706. Apply the smallest appropriate fix.717. Reproduce the original failure again.728. Run regression checks.739. Inspect the final diff.7475Do not hide failures by weakening tests, suppressing errors, deleting evidence, or claiming success without verification.7677## Security7879- Never expose secrets.80- Never commit credentials.81- Treat all external input as untrusted.82- Preserve authentication and authorization boundaries.83- Avoid leaking internal implementation details through errors.84- Review security implications whenever the skill touches users, data, credentials, networking, or deployment.8586## Completion Criteria8788A task using this skill is complete only when:8990- The requested behavior is implemented.91- Existing project conventions are preserved.92- Relevant static checks pass.93- Relevant tests pass or their absence is explicitly reported.94- Browser verification is performed when the task affects user-facing behavior.95- Security implications have been considered.96- The final diff has been inspected.97- Verified facts are clearly distinguished from assumptions or remaining uncertainty.