Pharo refactor

From KentBeck/SmalltalkGenie · View interactive version

Pharo refactor is an AI agent skill from the GitHub repository KentBeck/SmalltalkGenie. Refactor messy Pharo code safely through the genie MCP tools, working from the live image (no files). Use for renames, method extraction, moving behavior, or general cleanup of existing code.

How to use this skill

Skill file

Pharo refactor loop (live image, via the genie MCP tools)

Refactoring = change structure without changing behavior. The proof that

behavior is unchanged is a green test suite before AND after. All reads and

writes go through the genie MCP tools; there are no files. Change code only

via define_method / define_class / rename_class / remove_method /

eval, and read every change back to confirm it.

Loop

  1. Green baseline. Run run_test on the relevant class/package. If the code

you're about to touch has NO test coverage, STOP and write characterization

tests first (use the pharo-tdd skill) — you cannot refactor safely without

a safety net.

  1. Map impact. Before any rename/move/extract, find every caller and

implementor:

Make a list. Every item gets updated in this same session.

  1. One small change. Make a single structured edit. Read changed methods

back with get_method_source.

  1. Re-test. Run run_test (class, then package). Green → keep going.

Red → the trace shows what broke; fix or revert this one step before moving

on. Never batch unverified edits.

  1. Repeat steps 3–4 in small increments until the cleanup is complete.
  1. Done. Persist with save_image gated on the test package. Summarize the

before/after shape.

Common moves

symbol literal via the refactoring engine. It does NOT touch string literals,

so fix stringly-typed names by hand; and in a test that renames a class, refer

to the old name as 'Foo' asSymbol, never #Foo, or the test rewrites its

own assertion and self-mangles.

sender (from search_references), then remove_method the old one.

Rules

— do it under pharo-tdd, not here.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.