Refactor at the root
Skill AE86-Victory/webapp-engineering-skills/skills/refactor-at-the-root
Production-minded Agent Skills for responsive web design, root-cause refactoring, and maintainable app architecture.
npx -y skills add AE86-Victory/webapp-engineering-skills --skill refactor-at-the-rootAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
2 things to look at
- 15 days oldThe repository was created 15 days ago. New is not bad, but a brand new repository carrying a familiar-sounding name is the shape a typosquat arrives in, and there has been no time for anyone else to find a problem with it.
- 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.
What its author says it does
Copied from the file, not written here
Diagnose and implement the correct repair depth instead of stacking patches. Use when fixing recurring bugs, technical debt, duplicated exceptions, override-heavy CSS, growing conditionals, wrong ownership boundaries, fragile integrations, or code where another local fix would make the system harder to understand.
SKILL.md
6.1 KB, as published. Nobody here has run it
Refactor at the Root
Choose the smallest repair depth that eliminates the whole failure class. Optimize for a simpler resulting system, not the fewest changed lines.
1. Reconstruct the failure
- Reproduce the symptom or identify a concrete failing invariant.
- Trace inputs, state, ownership, and downstream effects through the relevant module boundaries.
- Inspect nearby exceptions, overrides, duplicated branches, TODOs, and recent fixes in the same path.
- Distinguish the visible failure site from the layer that owns the violated invariant.
Completion criterion: state the symptom, violated invariant, actual owner, and why the current structure permits the failure.
2. Detect a patch stack
Treat the code as a patch stack when one or more are true:
- the same concept is corrected in multiple children instead of one owner;
- a new branch exists only to counteract an earlier branch;
- route, device, customer, or state exceptions keep multiplying;
- CSS specificity, media queries, negative offsets, or overflow rules conceal upstream geometry;
- duplicated components drift because shared behavior has no single source of truth;
- a fix requires knowing historical accidents rather than domain rules;
- tests assert implementation accidents instead of stable behavior.
Read repair-depth.md when the boundary between a local repair and a refactor is uncertain.
Completion criterion: identify every existing patch that would become obsolete if the owner were repaired.
3. Choose the repair depth
Select explicitly:
| Depth | Use when | Required result |
|---|---|---|
| Local repair | One implementation is wrong and its owner/boundary is already correct | Correct the defect without adding a new exception |
| Module refactor | Responsibility, state, or layout ownership is misplaced inside one feature | Move the invariant to one owner and delete sibling patches |
| Shared abstraction refactor | Multiple modules implement the same policy with drift | Create one policy/component and leave variation as data or explicit strategy |
| Architecture refactor | The dependency direction or domain boundary itself causes repeated failures | Replace the boundary in staged, testable increments |
Effort, deadlines, and diff size affect sequencing, not diagnosis. If the durable fix is larger, stage it; do not mislabel another exception as the final solution.
Completion criterion: explain why the selected depth is sufficient and why the next shallower depth would preserve the failure class.
When the selected repair changes dependency direction, application layers, presentation ownership, construction, or stateful lifetimes, also apply $architect-maintainable-apps to define the target architecture before migration.
4. Define the target structure
Before editing, specify:
- the single owner of the invariant;
- the stable interface exposed to callers;
- which differences are real domain variation and which are accidental duplication;
- the obsolete paths, flags, overrides, or branches to remove;
- a migration order that keeps the system runnable.
Prefer deleting states and relationships over adding coordination. Prefer data-driven variation over copied control flow. Preserve public behavior unless the user requested a behavior change.
Completion criterion: the target can be described without referencing the old patches.
5. Lock the invariant with tests
- Add or tighten the smallest behavior/geometry/contract test that fails for the root cause.
- Cover representative siblings or callers when the bug class spans more than one instance.
- Test both sides of boundary conditions and the state transition that previously failed.
- Avoid snapshots as the only evidence when a semantic or geometric invariant can be asserted directly.
Completion criterion: the test would also fail for a future reintroduction of the same patch stack.
6. Refactor through the owner
- Change the owner or boundary first.
- Migrate callers to the repaired contract.
- Remove superseded exceptions in the same change.
- Keep temporary adapters narrow, named, and scheduled for removal within the active task when feasible.
- Re-read the diff for newly introduced flags, duplicated logic, and compatibility branches.
A successful refactor may change more lines while leaving fewer concepts, branches, and special cases.
Completion criterion: the root invariant has one owner and no touched caller still depends on the obsolete repair path.
7. Validate the resulting system
Run targeted tests first, then type, lint, build, and broader regression tests proportional to risk. Inspect the final code rather than stopping when tests turn green.
Verify:
- the original symptom is gone;
- sibling cases obey the same invariant;
- obsolete patches are deleted;
- public contracts remain stable or migrations are complete;
- control flow and ownership are simpler to explain;
- no unrelated subsystem was pulled into the refactor.
Completion criterion: provide evidence for behavior and for structural simplification.
Report
State the violated invariant, selected repair depth, owner changed, patches removed, tests run, and any intentionally deferred migration. Call out a tactical workaround honestly if scope or authority prevents the durable repair.
Failure signals
Stop and reassess when:
- the proposed fix adds another boolean, selector override, route check, or timing delay;
- the same correction must be copied to a second location;
- a child compensates for its parent's incorrect contract;
- a compatibility layer has no removal condition;
- the refactor introduces a generic abstraction before two concrete policies are understood;
- tests pass only because assertions were weakened or snapshots replaced;
- the diff is small but the explanation of behavior becomes longer.
Gives 0 of the 12 instructions most refactoring skills give
Counted across 521 of the 525 authors here whose files we hold, read 2026-08-06
- run tests after each changein 59 of 521, across 56 files
- write tests before refactoringin 27 of 521, across 24 files
- preserve external behaviorin 26 of 521, across 22 files
- remove dead codein 25 of 521, across 24 files
- make small incremental changesin 20 of 521, across 17 files
- break the implementation into tiny commitsin 18 of 521, across 5 files
- ask the user about alternative optionsin 17 of 521, across 4 files
- create a GitHub issue with the planin 17 of 521, across 4 files
- explore the repository to verify assertionsin 17 of 521, across 4 files
- interview the user about the refactorin 16 of 521, across 3 files
- check the codebase for test coveragein 16 of 521, across 3 files
- refactor one thing at a timein 16 of 521, across 12 files
Said here and by no other author read
- choose the smallest repair depth that eliminates the failure class
- reproduce the symptom or identify a failing invariant
- distinguish the failure site from the actual invariant owner
- identify existing patches that would become obsolete
- select repair depth based on failure scope
- specify the single owner and stable interface before editing
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once.