refactor

Installation
SKILL.md

Refactor

Author in a worktree. This skill edits repo files (atomic commits below) — work in a git worktree off main, never the primary checkout on the main branch (rules/worktree-authoring.md). Integrate with /ship.

A refactor can only fail two ways, and this skill exists to prevent both:

  1. Silent behavior change. Hallucinated equivalence (arr.filter().map()arr.reduce(), a moved await preserving order), a caller you never grepped, a narrowed type some caller violated at runtime. A green tsc is not proof — see the evidence gate.
  2. Scope sprawl. A "rename this type" becomes a 400-line rewrite mixing three concerns, unreviewable and unrevertible. Touching a file you didn't need to touch is a defect. Go deep on the chosen change (no compat shims, delete the old shape); never go wide beyond it.

The goal is a more maintainable codebase by this repo's definition (house rules below), with evidence — not a feeling from reading the diff — that behavior is unchanged. A refactor that silently alters behavior is net-negative maintainability: a hidden bug plus churn.

Run the tests — that's what the evidence is made of. This skill runs solo and infrequently: no other agent is sharing the local DB, the dev server, or any stateful fixture, so there is no contention reason to skip, sample, or defer a test. Prefer running the suite over reasoning about equivalence from reading the diff — a green run is the evidence; a plausible argument is not. Run tests eagerly and often: to establish the baseline, between every commit, and in full before you hand off. When a slower or DB-touching/E2E suite exists, running it is the safe default here, not a luxury — a db reset/seed or a suite that mutates local state is fine to run. Skipping a test you could have run is the evidence gap that lets a silent behavior change through.

Entry: census or targeted?

Census — the ask is vague ("clean this up", "reduce tech debt", "what's messy here?"): do a read-only scan first; make no edits. Look for: re-exports/barrels (grep both forms — see rules/code-style.md), types/constants inline instead of types.ts/constants.ts, single-file folders and one-function files, optional-field bags that should be discriminated unions, any/as density, dead exports (knip if present), god functions. Emit a prioritized plan — one line per atomic refactor, each with its importer fan-out, ordered by value/risk:

Installs
2
First Seen
Jul 14, 2026
refactor — jsolly/agent-skills