applying-refactors
Executes a refactor plan phase-by-phase on a dedicated branch with per-phase commits and mandatory reviewer checkpoints. Use when characterization-tests scaffold is complete and plan has phases ready to execute.
What this skill does
# Applying Refactors
## Overview
**Applying refactors IS executing each phase as a green, bounded-size commit with an adversarial review between phases.**
One branch. One commit per phase. One reviewer pass per phase. Zero silent advances. Zero phase >400 LOC unless explicitly acknowledged.
**Core principle:** Rollback is a first-class path, not an exception.
## Routing
**Pattern:** Chain
**Handoff:** user-confirmation per phase
**Next:** `verifying-refactors` (after last phase green)
## Task Initialization (MANDATORY)
- Subject: `[applying-refactors] Task N: <action>`
**Tasks:**
1. Verify git clean
2. Create refactor branch
3. For each phase:
a. Execute edits
b. Run verification command
c. Dispatch refactor-phase-reviewer
d. Commit phase
e. Checkpoint with user
4. Handoff to verifying-refactors
## Task 1: Verify git clean
Run `git status --porcelain`. Non-empty → abort: "Uncommitted changes exist. Commit or stash, then rerun."
## Task 2: Create branch
Read plan metadata for `branch_name`. Run:
```
git checkout -b <branch_name>
```
Already exists → abort: "Branch exists. Delete or rename, then rerun."
## Task 3: Phase loop
For each `Phase N` in plan (ascending):
### 3a. Execute edits
Apply changes per phase `files` and `description`. Edit only the listed files. Do not touch adjacent files even if tempting.
### 3b. Run verification
Run the phase's `verification.command`. Non-zero exit → stop; do not commit; diagnose. Options: rollback phase, adjust plan, abort run.
### 3c. Dispatch reviewer
Invoke `refactor-phase-reviewer` agent with:
- Phase N metadata from plan
- Diff of unstaged changes (`git diff`)
- `test_result`: stdout + exit code from the verification command (Check 4 of the reviewer requires this)
Reviewer returns `APPROVED` or `CHANGES_REQUESTED`.
`CHANGES_REQUESTED` → address feedback in-place, rerun verification, re-invoke reviewer. Max 2 retries → escalate to user.
### 3d. Commit
Per `references/phase-commit-protocol.md` format.
### 3e. Checkpoint
Print phase N summary: files changed, LOC, verification result, reviewer outcome. Ask user:
- `continue` → next phase
- `rollback phase` → `git reset --hard HEAD~1`, retry phase
- `abort run` → stop, leave branch
## Task 4: Handoff
After last phase's user `continue`, print run summary and hand off to `verifying-refactors`.
## Red Flags - STOP
- Editing files not listed in the phase
- Skipping reviewer dispatch
- `git commit --amend` during phase loop
- Running `git rebase` / `git reset --hard` outside rollback path
- Force-pushing the refactor branch
- Disabling hooks (`--no-verify`)
- Advancing on `CHANGES_REQUESTED` without addressing feedback
## Common Rationalizations
| Thought | Reality |
|---------|---------|
| "Test runner is slow — skip verification" | Green at every commit is the contract. No skip. |
| "Reviewer is picky, override" | Reviewer enforces the 400 LOC cap and test discipline. Overriding invalidates the plan. |
| "Merge plan phases for speed" | Phase boundary = rollback unit. Merging = losing rollback. |
| "amend to fix a typo" | Amend post-review = review bypass. New commit instead. |
## Flowchart
```dot
digraph apply {
start [shape=doublecircle, label="Start"];
clean [shape=diamond, label="Git clean?"];
abort_dirty [shape=doublecircle, label="Abort: dirty tree"];
branch [shape=box, label="Create branch"];
phase [shape=box, label="Execute phase N\nedits"];
verify [shape=diamond, label="Tests green?"];
review [shape=box, label="Dispatch reviewer"];
review_ok [shape=diamond, label="Approved?"];
commit [shape=box, label="Commit phase"];
checkpoint [shape=diamond, label="User action"];
next_phase [shape=box, label="Next phase"];
last [shape=diamond, label="Last phase?"];
handoff [shape=doublecircle, label="verifying-refactors"];
rollback [shape=box, label="git reset --hard HEAD~1"];
abort_user [shape=doublecircle, label="Abort: user"];
start -> clean;
clean -> abort_dirty [label="no"];
clean -> branch [label="yes"];
branch -> phase;
phase -> verify;
verify -> review [label="green"];
verify -> rollback [label="red"];
review -> review_ok;
review_ok -> commit [label="yes"];
review_ok -> phase [label="no, retry"];
commit -> checkpoint;
checkpoint -> last [label="continue"];
checkpoint -> rollback [label="rollback"];
checkpoint -> abort_user [label="abort"];
rollback -> phase;
last -> handoff [label="yes"];
last -> next_phase [label="no"];
next_phase -> phase;
}
```
## References
- `references/phase-commit-protocol.md`
Related in Code Review
gstack
IncludedFast headless browser for QA testing and site dogfooding. Navigate pages, interact with elements, verify state, diff before/after, take annotated screenshots, test responsive layouts, forms, uploads, dialogs, and capture bug evidence. Use when asked to open or test a site, verify a deployment, dogfood a user flow, or file a bug with screenshots. (gstack)
startup-due-diligence
IncludedLegal due diligence review for seed-stage and Series A startups (US, Delaware C-Corp focus). Supports both investor and founder perspectives. Capabilities include: (1) Interactive document review and issue spotting; (2) Document request list generation; (3) Cap table and SAFE/convertible note analysis; (4) Red flag identification with severity ratings; (5) Diligence report generation. TRIGGERS: due diligence, DD, startup investment, cap table review, Series A, seed round, investor diligence, legal review startup, SAFE analysis, convertible note, 409A, founder vesting.
interview-master
IncludedThis skill should be used when the user asks to "generate interview questions", "prepare for interview", "optimize resume", "conduct mock interview", "analyze git commits for resume", "generate resume from code", "review my resume", or mentions interview preparation, career assistance, or extracting project experience from git history. Provides comprehensive interview and career development guidance for both job seekers and interviewers.
fix-issue
IncludedFixes GitHub issues using parallel analysis agents for root cause investigation, code exploration, and regression detection. Reads issue context from gh CLI, searches codebase and memory for related patterns, generates a fix with tests, and links the resolution back to the issue via PR. Includes prevention analysis to avoid recurrence. Use when debugging errors, resolving regressions, fixing bugs, or triaging issues.
sf-apex
IncludedGenerates and reviews Salesforce Apex code with 150-point scoring. TRIGGER when: user writes, reviews, or fixes Apex classes, triggers, test classes, batch/queueable/schedulable jobs, or touches .cls/.trigger files. DO NOT TRIGGER when: LWC JavaScript (use sf-lwc), Flow XML (use sf-flow), SOQL-only queries (use sf-soql), or non-Salesforce code.
swift-development
IncludedComprehensive Swift development for building, testing, and deploying iOS/macOS applications. Use when Claude needs to: (1) Build Swift packages or Xcode projects from command line, (2) Run tests with XCTest or Swift Testing framework, (3) Manage iOS simulators with simctl, (4) Handle code signing, provisioning profiles, and app distribution, (5) Format or lint Swift code with SwiftFormat/SwiftLint, (6) Work with Swift Package Manager (SPM), (7) Implement Swift 6 concurrency patterns (async/await, actors, Sendable), (8) Create SwiftUI views with MVVM architecture, (9) Set up Core Data or SwiftData persistence, or any other Swift/iOS/macOS development tasks.