agentleFS
hamakyohamakyo/okf-skills/skills/refactor-safely/SKILL.md

refactor-safely

Skill2 starsChanged 3 months agoMITView on GitHub

Use when improving internal structure, readability, duplication, or maintainability without changing behavior. Keep diffs small and preserve public APIs, schemas, and user-visible behavior. Do not use when behavior, contracts, or migrations must change.

6 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

11 rules. 0 are common, 10 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 6 edited versions we read keep these.

  • 10

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this Skill when:

    line 10
  2. Distinctive:

    Do not use this Skill when:

    line 17
  3. Distinctive:

    Run or identify baseline tests when available.

    line 43
  4. Distinctive:

    Avoid mixing formatting-only changes with logic movement unless the repository already does so.

    line 45
  5. Very specific:

    If a behavior change becomes necessary, stop and switch to implement-feature or ask for confirmation.

    line 48
  6. Distinctive:

    Do not change behavior intentionally or accidentally.

    line 52
  7. Distinctive:

    Do not change public APIs, schemas, migrations, serialized formats, or user-visible text without explicit approval.

    line 53
  8. Distinctive:

    Do not perform broad cleanup outside the requested area.

    line 54
  9. Distinctive:

    Do not introduce new dependencies unless explicitly justified.

    line 55
  10. Distinctive:

    Do not remove tests to simplify the refactor.

    line 56
  11. Distinctive:

    Do not update OKF unless architecture, boundaries, or maintainership knowledge changed.

    line 57

“Common” is measured: kept by at least 6 in 10 of the 6 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Refactor Safely

When to use

Use this Skill when:

  • Reducing duplication.
  • Improving naming or structure.
  • Extracting helpers or simplifying control flow.
  • Preparing code for a later change while preserving behavior.

Do not use this Skill when:

  • User-visible behavior must change.
  • Public APIs, schemas, migrations, or data contracts must change.
  • The code is not covered enough to safely refactor and no validation plan exists.

Inputs

  • Target files, modules, or code smell.
  • Reason for the refactor.
  • Available tests or validation commands.
  • Relevant OKF docs when architecture or contracts are documented.

Required context

Before editing, read:

  • Existing code around the target area.
  • Tests that cover the behavior.
  • Relevant OKF architecture, data, or feature documents.
  • Public API, schema, or integration boundaries.

Workflow

  1. Define the behavior that must remain unchanged.
  2. Identify public APIs, schemas, data contracts, and external behavior that must not move.
  3. Run or identify baseline tests when available.
  4. Make the smallest meaningful structural change.
  5. Avoid mixing formatting-only changes with logic movement unless the repository already does so.
  6. Run targeted tests.
  7. Compare the diff to confirm behavior was preserved.
  8. If a behavior change becomes necessary, stop and switch to implement-feature or ask for confirmation.

Guardrails

  • Do not change behavior intentionally or accidentally.
  • Do not change public APIs, schemas, migrations, serialized formats, or user-visible text without explicit approval.
  • Do not perform broad cleanup outside the requested area.
  • Do not introduce new dependencies unless explicitly justified.
  • Do not remove tests to simplify the refactor.
  • Do not update OKF unless architecture, boundaries, or maintainership knowledge changed.

Completion checklist

  • Behavior to preserve was identified.
  • Public APIs and schemas were checked.
  • Diff is small and scoped.
  • Tests or validation were run.
  • Any residual risk is stated.

Expected final response

Report:

  • What was refactored.
  • Why behavior should be unchanged.
  • Files changed.
  • Tests or checks run.
  • Any risks or follow-up opportunities.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.