agentleFS
RidhuanDEVRidhuanDEV/claude-skills/shadow-refactor/SKILL.md

shadow-refactor

Skill1 starsChanged yesterdayMITView on GitHub

Behavior-Preserving Codebase Evolution. Use when safely refactoring legacy modules, introducing characterization tests, branch-by-abstraction, or AST-safe incremental cleanup within existing conventions. Do NOT use for enterprise topology redesign (shadow-architect/shadow-ea), migration TCO business cases (shadow-modernize), or root-cause bug hunting (shadow-debug).

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Default Access: Read-only repo & precedent discovery first (read_repository, run_local_tests).

    line 12
  2. Very specific:

    Convention Lock: Never introduce a new architecture layer, library, or pattern without an explicit ADR (§4.1).

    line 14
  3. Very specific:

    Read methodologies/CHARACTERIZATION-AND-SEMANTIC-EQUIVALENCE.md and playbooks/INVARIANT-LEDGER-AND-ROLLBACK.md for complex extractions:

    line 17
  4. Distinctive:

    Design Minimal Reversible Step: Use Branch-by-Abstraction, module-level Expand-Contract, or seam extraction with explicit rollback …

    line 22

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

/shadow-refactor — Behavior-Preserving Codebase Evolution

  • Owner: Safe, incremental structural improvements inside existing codebases without changing external contracts or local conventions.
  • Boundaries: Topology/ADR design (shadow-architect), M&A legacy due diligence & 3-5 yr TCO (shadow-modernize), bug root-cause diagnosis (shadow-debug), static lint/gate (shadow-quality).

1. Preconditions, Permissions & Failure Handling

  • Default Access: Read-only repo & precedent discovery first (read_repository, run_local_tests).
  • Missing Test Suite Rule: A missing test suite is a high risk, NEVER permission for an aggressive rewrite. Capture characterization tests (golden I/O) before modifying production paths.
  • Convention Lock: Never introduce a new architecture layer, library, or pattern without an explicit ADR (§4.1).

2. 8-Step Characterization & Refactor Playbook

Read methodologies/CHARACTERIZATION-AND-SEMANTIC-EQUIVALENCE.md and playbooks/INVARIANT-LEDGER-AND-ROLLBACK.md for complex extractions:

  1. Inventory Patterns: Record project runtime, formatting, naming, error envelope, and test idioms.
  2. Find 1–3 Precedents: Locate closest comparable modules in the repo; follow local module style over generic boilerplate.
  3. Declare Invariant Ledger: Lock API shape, validation rules, error codes, DB side effects, auth checks, and hidden frontend payload dependencies.
  4. Capture Characterization Tests: Record real observable inputs/outputs (PASS before refactoring).
  5. Design Minimal Reversible Step: Use Branch-by-Abstraction, module-level Expand-Contract, or seam extraction with explicit rollback instructions.
  6. Execute Compact Diff: Clean dead code inside modified files only; leave unrelated files untouched.
  7. Verify Semantic Equivalence: Re-run characterization tests, adjacent consumer/API contract tests, and shadow_gate.py.
  8. Report Proof: Output Invariant Ledger, diff scope, characterization exit codes, and residual risks.

3. Examples & Deterministic Gate

  • Happy Path: Split 400-line controller into service helpers -> precedent matched -> 6 characterization tests green before & after -> zero API/payload changes.
  • Ambiguous Case: Old module uses mixed CJS/ESM or conflicting validation styles -> document ambiguity in convention report and match target module's local style.
  • Failure / Must-Reject: Refactor silently changes domain validation threshold or touches unrelated files without characterization proof -> BLOCKED by refactor_characterization_gate.py.
python "shadow-refactor/scripts/refactor_characterization_gate.py" --self-test
python "shadow-refactor/scripts/refactor_characterization_gate.py" --verify-plan path/to/refactor-plan.json

4. Execution Approval & Intent Boundary (L0–L2)

  • Refactoring inside explicitly requested modules with passing characterization tests is L1_SAFE_VERIFICATION. Unrequested refactoring or editing files outside requested modules is L2: SCOPE_EXPANSION and requires explicit Monarch approval (shadow-monarch/scripts/execution_approval_gate.py).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.