agentleFS
SajidisrarSajidisrar/ios-claude-skills/skills/ios-refactor/SKILL.md

ios-refactor

Skill1 starsChanged 14 days agoMITView on GitHub

Refactor Swift code in this iOS codebase without changing behaviour — extracting types, splitting oversized files, moving logic to the right layer, removing duplication, or migrating a pattern across features. Use when asked to clean up, tidy, restructure, extract, split, simplify or modernise existing code, or when a file has grown past the point of being readable.

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    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:

    Check the tests that cover the code: If there are none, write them *first*, against current behaviour, and confirm they pass.

    line 16
  2. Very specific:

    Check docs/DECISIONS.md: If the structure you dislike is a recorded decision, argue with the decision rather than quietly reversing it.

    line 19
  3. Distinctive:

    Keep the public shape of a type stable while you move its internals, then change the shape in a separate step.

    line 43
  4. Distinctive:

    Run the tests after each step, not at the end.

    line 45
  5. Distinctive:

    Leave the comments that explain *why* attached to the code they explain.

    line 46

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “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

A refactor that changes behaviour is not a refactor, it is an undocumented change. The discipline below is what keeps them apart.

Before touching anything

  1. Name the goal in one sentence. "Move date formatting out of the view into the view model." If you cannot, the change is not a refactor — it is a redesign, and needs discussion first.
  2. Check the tests that cover the code. If there are none, write them first, against current behaviour, and confirm they pass. Those tests are the only proof the refactor was safe.
  3. Check docs/DECISIONS.md. If the structure you dislike is a recorded decision, argue with the decision rather than quietly reversing it.

Where things belong

Most refactors in this codebase are one of these five moves:

SmellMove
Formatting, string building or derived flags in a viewInto the view model as a computed property
Business rules or validation in a view modelOnto the model (validationMessages) or the repository
Endpoint construction or cache keys in a view modelInto the feature's Data folder
The same helper in two featuresDown into Core — never sideways between features
A repository over ~350 linesSplit by concern: reads, writes, replay — same type, // MARK: sections, or an extension per concern in separate files

Things that must not move: URLSession out of Core/Networking, tokens out of Core/Auth, cache and outbox access out of repositories.

Method

  • One kind of change per commit. Renaming and extracting and re-ordering in one diff is unreviewable.
  • Extract by copying, redirecting call sites, then deleting the original — never by editing in place and hoping.
  • Keep the public shape of a type stable while you move its internals, then change the shape in a separate step.
  • Run the tests after each step, not at the end.
  • Leave the comments that explain why attached to the code they explain. Losing the "why the actor is here" comment costs more than the refactor gains.

What counts as done

The diff should read as obviously equivalent. If a reviewer has to reason about whether behaviour changed, split the change up further.

Verification

  • Tests existed before, still exist, and still pass unchanged. Changing a test to match the refactor means behaviour changed — stop and say so.
  • No new dependency across the layer boundaries.
  • No feature now imports another feature.
  • Public behaviour identical: same states, same error copy, same requests.
  • Comments explaining non-obvious decisions were carried across.
  • project.pbxproj is untouched. The source folders are synchronised, so a file or folder move needs no project-file change; if one appears in the diff, explain why.
  • The summary says explicitly what did not change.

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.