code
Polish code before review and restructure it without changing what it does, in small verified steps, judged through the same six lenses by reviewers that did not write it
- Carries
- skillsagentsresources
this project
uze code@aithis machine
uze install code@ai -mWhich skill, when
Two skills with opposite contracts:
| Ask yourself | Use | It may change behavior |
|---|---|---|
| "is this ready for someone else to read?" | polish | yes, with proof |
| "I want this part to have a different shape" | refactor | never |
A typical feature goes implement → polish → open the request. When
polish finds something structural that is too big to fix in passing, it
does not do it: it recommends a refactor in its report, and you decide
whether that is now, in a separate request, or later.
polish
Runs on the current branch against its base by default, or on the paths you name, or on the whole codebase when you ask for a sweep. It fixes what it confirms unless you ask it only to assess. Emphasis ("be picky", "mostly performance") and a subagent budget are arguments, not prompt boilerplate.
- Reads the project's rules and gate, and runs the gate once as the baseline.
- Hands the code to reviewers that did not write it - the plugin's
revieweragent, given the diff, the rules and the lenses, never the reasoning behind the code. - Judges each finding on evidence: confirmed, rejected (with the reason, listed so you see what the author dismissed) or unproven.
- Fixes the confirmed ones, one per green commit: a bug with the test that
shows it first (
fix:), padded tests replaced by real ones (test:), local structure withrefactor's discipline (refactor:). - Reviews its own fixes once more, with a fresh reviewer, and reports.
refactor
Changes structure and nothing else. A change that breaks either promise is not a refactoring, whatever its commit says:
- Behavior is preserved, proved by the project's gate, not by reading the diff.
- Every step can be undone: one transformation, a green gate, one commit.
A bug found on the way is recorded and fixed in a fix: commit of its
own.
It works in any language because it asks what safety net the code has, not what language it is:
| The code has | Steps may be |
|---|---|
| strict static types | larger: the compiler finds every caller |
| partial or optional types | medium: search where the checker is blind |
| no static types | small: tests after every move |
| dispatch by name (reflection, DI, templates, config keys) | smallest: search the name as text everywhere |
Where nothing pins the behavior, it writes characterization tests first, green against the old code.
Sized before started, and who runs it
| Size | The plan lives | Executed by |
|---|---|---|
| local | in the session | the session |
| spread | a Mikado graph in the git directory, never committed | the plugin's refactor-executor agent, given only the plan |
| aggressive | an OpenSpec change | openspec's auto |
Planning always stays with you, because it needs the conversation. The execution and the final review do not, and are better without it: every final diff goes to an independent reviewer.
The Mikado method: try the goal, note what broke, revert, do the leaves first. The tree is green between any two steps.
Your project decides what green means
Before anything else, both skills read the project's own rules
(AGENTS.md, architecture docs, decision records) and its CI, and adopt
the exact commands that block a merge as the gate. Your rules win over the
skills'.
Decisions they take, and the ones they do not
Easy to undo (names, extractions, moves inside a module, which of two fixes for a bug): decided and recorded. Hard to undo (a persisted format, a public interface, a new dependency, removed behavior, a moved trust boundary): decided by you, or left for you with a recommendation. Each skill stops on a short closed list of conditions, and finishing a step is not one of them.
Six lenses
Asked of every change, so they never have to go into a prompt again:
- correctness: edges, error paths, races, leaks, every platform the project supports - with a concrete scenario or it is not a finding
- security: checks still before use, on every path; untrusted input; secrets
- architecture: the project's own rules, dependency direction, boundaries, rules kept as tests
- performance: no number, no claim
- quality: names, smells worth acting on, dead code, workarounds
- tests: would this test fail if the code broke, or does it only pad coverage?
The report
Same shape every time, every section present even when it says none:
the gate and its result, what changed, what was decided or rejected, what
waits for you, what was found and left alone.
Skills
polish
model + userMake code ready for review - put a branch, a module or a whole codebase through six lenses (correctness, security, architecture, performance, quality, tests) with reviewers that did not write it, prove each finding, and fix the confirmed ones in small verified steps. Use before opening a merge or pull request, after finishing an implementation, when asked to review an implementation and fix what turns up, or to hunt hidden bugs, dead code, workarounds, performance or security problems and tests that only pad coverage - "analisa a implementação", "revisa essa branch", "vê se tem gambiarra", "revisa esse PR", "pente fino", "limpa essa parte", "seja chato". Also assesses without changing anything, when asked to. The project's own rules and gate decide what is wrong and what green means. Not for a deliberate restructuring with a goal of its own (that is `refactor`), not for writing the feature, and not for committing or opening the request (the `git` plugin's `commit` and `pr`).
Needs A git repository, any language. Runs its reviewers as subagents where the harness can start them, and in the same session, saying so, where it cannot.
Read polish/SKILL.mdrefactor
model + userChange the structure of existing code without changing its behavior - from a rename across a module to a boundary moved across a codebase - in small verified steps, with every decision the plan did not make recorded for review. Use when someone asks to refactor, restructure, extract, split, untangle, decouple or migrate a module or an interface, to pay down technical debt, or says "refatora isso", "reorganiza esse módulo", "quebra esse arquivo". Language-agnostic - the project's own gates and docs decide what green means. Not for adding or changing behavior (that goes in its own step, before or after, never in the same one), not for a quality pass over a branch or an implementation before review (that is `polish`), not for working an existing OpenSpec task list (that is the `openspec` plugin's `auto`), and not for committing the result (that is the `git` plugin's `commit`).
Needs A git repository, any language. Uses a language server, ast-grep or comby for mechanical changes when one is present, and falls back to search and edit when none is.
References mechanical-change.md, mikado.md, safety-net.md
Read refactor/SKILL.md