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

refactor-safely

Skill3 starsChanged 10 days 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.

23 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use audit-test-suite, change-data-safely and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • yaohuangguanSkill

    audit-test-suite

    Find where an existing test suite is weak and decide what to test next, ranked by risk. Use this when asked to add missing tests, find gaps, raise coverage, assess test quality or see which areas are thin, even if the request only mentions a coverage percentage.

    Also in 3 projects that use this

  • yaohuangguanSkill

    change-data-safely

    Change a database schema or stored data without breaking running code or losing data. Use this for any migration, new or changed column, backfill, bulk update, delete, index, or change to a stored format, including in small projects. Data mistakes are often impossible to undo.

    Also in 3 projects that use this

  • NVIDIASkill

    debug-issue

    Use when the user asks to debug, investigate, or fix a GitHub issue or supplies a repository bug report.

    Also in 6 projects that use this

  • MicrosoftSkill

    fix-flaky-test

    Reproduces and fixes flaky or quarantined tests. Tries local reproduction first (fast), then falls back to CI reproduce workflow (reproduce-flaky-tests.yml). Use this when asked to investigate, reproduce, debug, or fix a flaky test, a quarantined test, or an intermittently failing test.

    Also in 3 projects that use this

  • SauravSrivastavSkill

    debug-failure

    Diagnose a failing test, command, or runtime behavior using evidence and produce a minimal verified fix.

    Also in 3 projects that use this

  • Codagent-AISkill

    implement-change

    Implements an approved change in one continuous session, with tiered test runs. Use when asked to implement a change from its approved definition, or to invoke codagent:implement-change.

    Also in 5 projects that use this

  • +6 more from yaohuangguan

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 21 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 21 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.