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).
In this repository51 other files it gives its agents.
- antislop-codeSkill
- antislop-copywritingSkill
- antislop-humanSkill
- antislop-layoutmobileSkill
- antislopSkill
- antislop-uiSkill
- context7Skill
- handoffSkill
- shadow-accessibilitySkill
- shadow-apiSkill
- shadow-architectSkill
- shadow-authSkill
- shadow-bootstrapSkill
- shadow-browserSkill
- shadow-cacheSkill
- shadow-compatSkill
- shadow-concurrencySkill
- shadow-dataSkill
- shadow-dbSkill
- shadow-debugSkill
- shadow-designSkill
- shadow-discoverySkill
- shadow-docSkill
- shadow-domainSkill
- shadow-eaSkill
- shadow-evalSkill
- shadow-finopsSkill
- shadow-gitSkill
- shadow-grcSkill
- shadow-handoverSkill
- shadow-integrateSkill
- shadow-maintainSkill
- shadow-mobileSkill
- shadow-modernizeSkill
- shadow-monarchSkill
- shadow-observeSkill
- shadow-opsSkill
- shadow-perfSkill
- shadow-planSkill
- shadow-pmoSkill
- shadow-presalesSkill
- shadow-privacySkill
- shadow-qualitySkill
- shadow-realtimeSkill
- shadow-releaseSkill
- shadow-resilienceSkill
- shadow-searchSkill
- shadow-secSkill
- shadow-supplychainSkill
- shadow-testSkill
- shadow-uatSkill
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
- Very specific: line 12
Default Access: Read-only repo & precedent discovery first (read_repository, run_local_tests).
- Very specific: line 14
Convention Lock: Never introduce a new architecture layer, library, or pattern without an explicit ADR (§4.1).
- Very specific: line 17
Read methodologies/CHARACTERIZATION-AND-SEMANTIC-EQUIVALENCE.md and playbooks/INVARIANT-LEDGER-AND-ROLLBACK.md for complex extractions:
- Distinctive: line 22
Design Minimal Reversible Step: Use Branch-by-Abstraction, module-level Expand-Contract, or seam extraction with explicit rollback …
≈ “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.
Files
/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:
- Inventory Patterns: Record project runtime, formatting, naming, error envelope, and test idioms.
- Find 1–3 Precedents: Locate closest comparable modules in the repo; follow local module style over generic boilerplate.
- Declare Invariant Ledger: Lock API shape, validation rules, error codes, DB side effects, auth checks, and hidden frontend payload dependencies.
- Capture Characterization Tests: Record real observable inputs/outputs (
PASSbefore refactoring). - Design Minimal Reversible Step: Use Branch-by-Abstraction, module-level Expand-Contract, or seam extraction with explicit rollback instructions.
- Execute Compact Diff: Clean dead code inside modified files only; leave unrelated files untouched.
- Verify Semantic Equivalence: Re-run characterization tests, adjacent consumer/API contract tests, and
shadow_gate.py. - 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.json4. 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 isL2: SCOPE_EXPANSIONand requires explicit Monarch approval (shadow-monarch/scripts/execution_approval_gate.py).
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
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.

