safe-refactor

Automate behavior-preserving code refactors with a baseline-test, edit, retest, and commit loop.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/edri2or/project-life-132 --skill safe-refactor-edri2or
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: safe-refactor
Source: https://github.com/edri2or/project-life-132/tree/main/exported-skills/safe-refactor
Command: npx skills add https://github.com/edri2or/project-life-132 --skill safe-refactor-edri2or

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Safely refactors a module through a baseline-test → edit → retest → self-correct → commit loop. Use when the user asks to refactor code, clean up a module, rename a class, extract a function, or restructure code without changing behaviour.

Core Features & Use Cases

  • Baseline-driven refactoring workflow that prevents regressions by running tests before edits.
  • Self-correcting loop with up to 3 attempts to fix failures and keep changes targeted.
  • Plan-first execution with explicit user approval before edits (plan_mode_required governance).
  • Linting and targeted test runs on changed files, with guarded commits.

Quick Start

Approve a refactor plan, then permit the agent to execute edits, run lint and tests, and commit only if all tests pass.

Frequently Asked Questions about safe-refactor

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I refactor code without changing behavior or breaking existing tests?

Safe refactoring prevents behavior changes by running baseline tests before edits, then retesting and self-correcting up to 3 times before committing. This loop ensures your refactor preserves the original module's logic across common scenarios.

What is the safest way to rename a class or extract a function from a module?

The safest refactor uses a plan-first workflow requiring explicit approval before edits, followed by lint and targeted test runs on changed files. Commits are guarded so they only happen when all tests pass.

How do I automate a code cleanup and restructure while preventing regressions?

Automated refactoring prevents regressions by establishing a baseline test run, applying edits, and entering a self-correcting loop if tests fail. It commits changes only after verifying the targeted tests pass.

Do I need to approve a refactoring plan before the agent edits my code?

Yes, plan-first execution requires explicit user approval before any edits are made. This governance ensures you review the intended renames, extractions, or restructures before the agent runs lint and tests.

What happens if lint or tests fail during a module restructure?

When tests fail during a refactor, the agent enters a self-correcting loop and attempts to fix the failures up to 3 times. It keeps changes targeted and will only commit once all targeted tests pass.

Can I use this for large modular restructures or only small function extractions?

You can use this for both small function extractions and large modular restructures. The baseline-test, edit, and retest loop applies to any behavior-preserving code changes as long as you provide an explicit plan.