Skill
refactor-safely
Refactor code in any language with a beauty-first, safety-first style while preserving behavior. Use when the user asks to clean up, beautify, restructure, harden, or make code more readable without changing functionality.
Install this skill
npx skills add adiutama/skills --skill refactor-safely Invoked as /refactor-safely [file-path|folder-path|symbol-name].
Refactor safely
Philosophy
Treat code as a poem: structure matters. Beauty and effectiveness co-exist.
Never treat readability as optional. Small ugly code compounds and spreads.
Non-negotiables
- Preserve external behavior unless the user explicitly asks for behavior change.
- Improve clarity and maintainability while keeping performance at least neutral.
- Raise security posture when possible (input handling, escaping, validation, secret handling, error boundaries).
- Keep edits intentional, minimal, and reversible.
- Do not rewrite entire modules when focused refactors achieve the same result.
Workflow
Scope
- Resolve target from argument or user context.
- If scope is ambiguous, ask one concise clarification and stop.
Establish baseline
- Read current implementation first.
- Identify behavior contracts (I/O shape, side effects, errors, edge cases).
- If tests exist, run the smallest relevant set before edits.
Refactor in passes
- Apply the checklist in
references/checklist.md. - Prefer small coherent commits of change (structure, naming, simplification, safeguards).
- Keep public APIs stable unless instructed otherwise.
- Apply the checklist in
Verify
- Run relevant tests/checks after edits.
- If no tests exist, add lightweight characterization tests when feasible.
- Confirm no accidental functional drift.
Report
- Summarize what changed and why it is cleaner/safer.
- Explicitly note any trade-offs.
- If verification was partial, state what remains to validate.
Output format
Use this structure in responses:
- Intent: one sentence on what was improved.
- Refactor changes: 3-7 bullets grouped by structure/readability/safety.
- Behavior guarantee: what was done to preserve functionality.
- Validation: tests/checks run (or what could not be run).
- Residual risk: short note if any uncertainty remains.
skills/refactor-safely/SKILL.md