skills/refactor/SKILL.md
Branch-aware simplification. On feature branches, compare against base and simplify the diff before merge. On primary branch, scan for the highest impact deletion, consolidation, or boundary improvement. Use when: "refactor this", "simplify this diff", "clean this up", "reduce complexity", "pay down tech debt", "make this easier to maintain", "make this more elegant", "reduce the number of states", "clarify naming". Trigger: /refactor.
npx skillsauth add phrazzld/agent-skills refactorInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Reduce complexity without reducing correctness. Favor fewer states, clearer names, stronger invariants, better tests, and current docs. Deletion first, then consolidation, then abstraction, then mechanical cleanup.
Delegation floor applies: probe the roster first; dispatch two or more
providers for substantive work; direct solo only for mechanical, emergency,
user-forbidden, or fewer-than-two-providers cases. See
harnesses/shared/AGENTS.md (Roster).
Local lane guidance: Use one lane to map complexity and another to challenge behavior-preservation risk; add a builder lane for the selected change.
Completion evidence core applies: use harnesses/shared/AGENTS.md
(Completion Evidence) as the universal evidence shape, then fill the local
fields for behavior preservation, deletion/consolidation choice, and residual
risk.
When invoked after implementation or review, run a behavior-preserving deslop pass before broader refactoring. Remove:
Keep behavior unchanged unless fixing a clear bug. If cleanup would alter
behavior, stop and route the finding back through /shape or /implement.
Detect the current branch and primary branch first:
git rev-parse --abbrev-ref HEADgit symbolic-ref --short refs/remotes/origin/HEAD | sed 's#^origin/##'
(fallback main, then master)If current branch != primary branch: run Feature Branch Mode. If current branch == primary branch: run Primary Branch Mode.
If current branch resolves to HEAD, the primary branch cannot be discovered,
or the detected base is ambiguous, stop and require --base <branch>. Fail
closed rather than computing the wrong diff.
--base <branch> overrides detected base branch for feature-branch comparisons.
--scope <path> limits analysis and edits to one subtree.
--report-only disables file edits.
--apply allows edits in primary-branch mode (otherwise report + backlog shaping only).
Detailed simplification methodology lives in references/simplify.md.
Goal: simplify what changed between base...HEAD before merge.
git diff --stat <base>...HEADLaunch at least three subagents in parallel:
Each subagent returns: top findings, one recommended change, confidence, risk.
When a finding is a design-quality concern, dispatch the matching lens from
harnesses/shared/references/lenses.md (ousterhout/grug for depth & complexity,
carmack for scope, beck/cooper for test shape) as an ad-hoc critic returning
finding · evidence file:line · impact.
Rank opportunities by:
(complexity removed * confidence) / implementation risk
Prefer:
--report-only)Dispatch a builder subagent for exactly one bounded refactor. Each refactor must include:
Minimum:
If available, run assess-simplify and require complexity_moved_not_removed=false.
main / master)Goal: find the single highest-impact simplification for the codebase itself. This mode is designed to be safe for scheduled runs.
Use evidence from:
git log --name-only)Launch at least three subagents in parallel:
Invoke /research for the target domain before final recommendation. Do not
assert architecture choices from memory.
Default (safe): no code edits. Instead:
backlog.d/) with oracleIf --apply is explicitly set:
## Refactor Report
Mode: feature-branch | primary-branch
Target: <branch or scope>
### Candidate Opportunities
1. [winning candidate] — complexity removed, risk, confidence
### Optional Runners-Up
1. [runner-up]
2. [runner-up]
### Selected Action
[what was applied, or backlog item created]
### Verification
[tests/lint/assessment results]
### Completion Gate
- Exact developer/operator behavior changed: simplification effect or shaped backlog outcome created.
- Evidence that proves it: diff stat, test output, report finding, or command result proving the change.
- Exact command/path/route exercised: command, file path, route, or tool call inspected.
- Repo-fit check: live repo boundary, pattern, or deletion/consolidation contract followed.
- Residual risk: unverified path, remaining complexity, or none with reason.
Completion evidence core applies: behavior changed or verified, live evidence,
exact command/path/route, repo-fit check, and residual risk. See
`harnesses/shared/AGENTS.md` (Completion Evidence).
Local fields require developer/operator behavior wording for internal-only
refactors.
### Residual Risks
[what remains and why]
development
Lightweight evidence-backed retro and catch-up reports for a current repo, branch, PR, backlog slice, or recent agent session. Use when the user asks for a debrief, catch me up, what changed, why it matters, product implications, end-user implications, developer experience implications, current app state, backlog state, workspace state, alternatives considered, or context rebuild after losing the thread. Trigger: /debrief.
testing
Capture agent-session work records as local JSONL audit evidence. Links a backlog/spec, branch, commits, review verdicts, QA/demo evidence, transcript refs, and shipped ref without storing raw private transcripts. Use when: "trace this work", "write work record", "agent session trace", "journal this delivery", "link transcript evidence". Trigger: /trace, /journal.
data-ai
Turn proven agent-session patterns into first-party Harness Kit skills. Use when: "skillify this conversation", "make this into a skill", "generate a skill from current transcript", "extract reusable workflow". Trigger: /skillify.
testing
Run one targeted, read-only architecture or quality critique through a named lens from the shared rubric. Use when: "critique this module", "run an Ousterhout pass", "lens critique", "architecture critique". Trigger: /critique.