# Refactor

> Constrains the Agent to follow a safe refactoring process — guarantee functional equivalence while improving code quality.

- Skill: `aquifer-sea/refactor` (Agent Skill, multi-file: 5 files)
- Install (CLI): `npx skillmds@latest add aquifer-sea/refactor`
- Raw SKILL.md: https://api.skillmd.com/api/skills/aquifer-sea/refactor/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: Aquifer-sea (https://skillmd.com/u/aquifer-sea)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/aquifer-sea/refactor

---


# Code Refactor

Constrains the Agent to perform safe code refactoring: guarantee functional equivalence while improving code quality.

<PIPELINE>

## Step 1: Inversion (Requirements Alignment)

Before refactoring, you must check every item in `assets/checklist.yaml`.

<HARD-GATE>
If the user has not specified the refactoring goal (readability? performance? DRY?), you must ask first.
If you cannot confirm which behaviors must remain unchanged, you must block and ask.
Do NOT start refactoring without knowing what must NOT change.
</HARD-GATE>

## Step 2: Generator (Generate Refactoring Plan from Template)

Your output must strictly follow the format in `assets/template.yaml`.
Must include: refactoring goal, impact analysis, refactoring steps (with diff), behavioral equivalence checklist.

## Step 3: Tool Wrapper (Security Fence)

If you need to execute code during refactoring for verification, check `references/security.yaml` first.
Do not delete tests or remove error handling logic during refactoring.

## Step 4: Reviewer (Self-Audit Loop)

Audit your refactoring output against `references/guidelines.yaml`.
Key checks: is the behavior equivalent? Are public APIs unchanged? Is code complexity reduced?
Roll back and regenerate if non-compliant, up to 3 retries.

</PIPELINE>

