Skip to content
Agentmart
Submit a tool

hm-l2-refactor

Decide between surgical and structural refactoring with scope, safety, and rollback planning.

Skill by shynlee04

IndexedMIT★ 51
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/shynlee04-hm-l2-refactor

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Decide between surgical and structural refactoring with scope, safety, and rollback planning. Use when cleaning code, restructuring modules, improving architecture, when code has grown organically and needs organization, when technical debt is accumulating, or when the user says "this code is a mess" or "clean this up." Even when they don't explicitly say "refactor." Triggers: "refactor", "clean up code", "restructure", "improve architecture", "technical debt", "code organization", "surgical refactor", "structural refactor". NOT for rewrites that change behavior or for trivial formatting fixes.

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found
Runs as
Shell scripts

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/hm-l2-refactor

What's inside

Skill name
hm-l2-refactor
Description
Decide between surgical and structural refactoring with scope, safety, and rollback planning. Use when cleaning code, restructuring modules, improving architecture, when code has grown organically and needs organization, when technical debt is accumulating, or when the user says "this code is a mess" or "clean this up." Even when they don't explicitly say "refactor." Triggers: "refactor", "clean up code", "restructure", "improve architecture", "technical debt", "code organization", "surgical refactor", "structural refactor". NOT for rewrites that change behavior or for trivial formatting fixes.
License
MIT
Metadata
role: domain-execution · layer: 2 · pattern: P2 · version: 1.0.0
Instructions
154 lines in SKILL.md · view on GitHub

Before installing

  • Ships executable scripts

Agent Skills spec issues

  • allowed-tools: must be a space-separated string

Files (7)

  • SKILL.md
  • evals.json · evals/
  • rich-gate-scorecard.md · metrics/
  • refactor-runbook.md · references/
  • refactor-taxonomy.md · references/
  • safety-checklist.md · references/
  • validate-skill.sh · scripts/

SKILL.md (first lines)

## Overview

Decision framework for choosing between surgical and structural refactoring approaches. Use when cleaning up code, restructuring modules, addressing technical debt, or reorganizing grown-organic codebases. Produces scoped refactoring plans with rollback strategies and safety guardrails.

## The Iron Law

```
Refactoring without tests is restructuring. Restructuring without rollback is reckless.
```

# Refactor Decision Framework
## On Load

1. Read `references/refactor-taxonomy.md` — surgical vs. structural refactor decision tree
2. Read `references/safety-checklist.md` — pre-refactor safety checks

## Refactor Taxonomy

## Gated Refactor Protocol

Adapted from GitHub `awesome-copilot` `refactor-plan`: refactors are planned as deterministic, reversible sequences with verification between changes. Do not start by editing code. First map affected files, dependency direction, test coverage, and rollback.

| Gate | Required output | Stop condition |
|------|-----------------|----------------|
| Scope map | Files/functions/modules touched and why behavior stays unchanged | Unknown callers or side effects |
| Sequence | Ordered steps: types/interfaces first, implementation moves second, tests/fixtures last | Steps cannot be independently verified |
| Safety net | Existing tests or characterization tests before structural moves | No way to detect behavior drift |
| Rollback | Per-step rollback command or commit boundary | Rollback requires blanket reset/clean |
| Verification | Command after each step and final integration command | Verification unavailable or unrelated |

Use `references/refactor-runbook.md` for the execution worksheet.

### Surgical Refactor

| Attribute | Value |
|-----------|-------|
| Scope | Single function, variable rename, inline extraction |
| Risk | Low |
| Tests | Existing tests must pass before and after |
| Rollback | `git checkout -- <file>` |
| Time | Minutes |

**Examples:** Rename variable, extract function, remove dead code.

### Structural Refactor

| Attribute | Value |
|-----------|-------|
| Scope | Module boundaries, dependency direction, file moves |
| Risk | High |
| Tests | Existing + new integration tests required |
| Rollback | `git revert <commit>` or branch delete |
| Time | Hours to days |

**Examples:** Split god object, invert dependency, introduce interface.

## Decision Tree

```
Does the change alter behavior?
├── YES → This is NOT a refactor. Stop. Write spec first.
└── NO → How many files are affected?
    ├── 1 file, 1 function → Surgical
    └── Multiple files or modules → Structural

Structural: Are tests comprehensive?
├── YES → Proceed with branch + incremental commits
└── NO → Write tests FIRST, then refactor
```

## Safety Checklist

- [ ] All existing tests pass before refactor
- [ ] Refactor is on a branch (not main)
- [ ] Each incremental step is committed
- [ ] Tests pass after each commit
- [ ] Rollback plan is known (branch name or commit hash)
- [ ] Affected dependency graph is mapped before moving modules
- [ ] Verification command is attached to every refactor step

## Rollback Protocol

```bash
# If tests fail after refactor:
git diff HEAD~1  # See what changed
git checkout HEAD~1 -- <affected-files>  # Revert specific files
```

Avoid blanket reset/clean operations in agent worktrees. Prefer file-specific checkout for files changed in the current refactor step, or revert the step commit when the workflow allows commits.

## RICH Gate Source Decisions

| Source | Decision | Local adaptation |
|--------|----------|------------------|
| `github/awesome-copilot` refactor-plan | ADOPT | Safe sequence, affected-file/dependency map, verification between changes, and rollback worksheet. |
| `addyosmani/agent-skills` incremental implementation | ADAPT | Small reversible steps and characterization tests are used as safety gates. |
| GitHub agent skill resource model | ADAPT | Runbook and evals carry detailed reusable material instead of bloating SKILL.md. |

## Independence Notes

This skill works in any Git-backed end-user project. If no git repository exists, replace commit rollback with copied-file checkpoints and document that rollback is degraded. Do not assume GSD, BMAD, or HiveMind phase state.

## Anti-Patterns

| Anti-Pattern | Detection | Correction |
|-------------|-----------|------------|
| **The Behavior Changer** | Refactor changes output or side effects | Stop. This is a rewrite, not a refactor. Write spec. |
| **The Testless Restructure** | Restructures without running tests | Run tests before EVERY step |
| **The Mega-Commit** | Refactors 20 files in one commit | Commit after each file or logical unit |
| **The No-Rollback** | Works on main without branch | `git checkout -b refactor/<name>` before touching code |

## Reference Map

| File | When to Read |
|------|-------------|
| `references/refactor-taxonomy.md` | Choosing between surgical and structural |
| `references/safety-checklist.md` | Pre-refactor safety verification |
| `references/refactor-runbook.md` | Step worksheet, dependency map, rollback table |

From shynlee04/hivemind-plugin, MIT.

More from shynlee04/hivemind-plugin

Signals

Stars
51
Forks
16
Open issues
21
Last commit (this folder)
May 7, 2026 (5 months ago)

From GitHub (fetched Oct 24, 2026).

Details

Version
1.0.0
License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from shynlee04

Cite this page

hm-l2-refactor skill. Agent Mart. https://agentmart.dev/skills/shynlee04-hm-l2-refactor (last updated 2026-10-24)