Code hygiene refactor

From Sistema2D/FrameCode-VibeWork · View interactive version

Code hygiene refactor is an AI agent skill from the GitHub repository Sistema2D/FrameCode-VibeWork. Select a bounded, behavior-preserving cleanup batch, and sanitize the code of an item the user asked to remove. Use when removing duplication, dead code or stale files, or when the user asks to remove or discontinue a button, field, screen, route or feature. Do not use for feature work or large rest

How to use this skill

Skill file

SKILL: Code Hygiene Refactor

Purpose

Drive active cleanup of duplication, stale files, unnecessary code, oversized modules, and retroactive technical debt while preserving behavior. This skill is a Markdown-only operational tool: it tells the agent what to inspect, what to block, and what evidence to record.

Activation Triggers

Load this skill when:

Inputs

Active plan and scope, changed-path and ownership evidence, similar-code search, dependency/consumer references, focused behavior checks, and rollback or restoration source for removals.

Non-Negotiable Rules

Proportionality Check

Before creating a utility, service, wrapper, component, dependency, file, layer, or parallel mechanism, evaluate in order:

  1. Is the behavior necessary in the current scope?
  2. Does the codebase already contain a complete or partial solution?
  3. Does the language, framework, platform, or infrastructure provide a native capability?
  4. Does an already installed dependency solve it adequately?
  5. Only then, is new code justified?
proportionality_gate: required
ladder:
  - in_scope
  - existing_solution
  - native_capability
  - installed_dependency
  - justified_new_code
advisory_when: bounded_direct_change

For any non-trivial increase in technical complexity, record:

This check is mandatory when adding a dependency, abstraction, service, wrapper, architectural layer, or parallel workflow. It is advisory for small direct changes whose implementation is self-evidently bounded. It must never reduce security, privacy, accessibility, traceability, validation, audit, compliance, data integrity, or risk-required tests.

Do not create a separate anti-overengineering skill unless repeated evidence shows this integrated check cannot cover the workflow.

Hygiene Scan

Use the smallest scan compatible with the risk:

| Scan | Use when | Evidence |

|---|---|---|

| Local | One file or one function is changing. | Similar-code search, direct callers, before/after behavior. |

| Module | A component, route, service, prompt pack, or folder is changing. | Inventory table, imports/callers, tests, duplication candidates. |

| Systemic | Multiple modules, legacy migration, or retroactive adoption. | Dependency/impact map, phased plan, rollback, characterization tests. |

Findings Matrix

Classify each finding before editing:

| Finding | Required action |

|---|---|

| Duplicate code | Extract only when the shared rule is truly identical; otherwise document intentional variation. |

| Large file | Load anti-monolith-guard; split by responsibility before adding behavior. |

| Dead code | Mark CANDIDATE_FOR_REMOVAL; remove only after validation. |

| Stale file | Mark authoritative source and obsolete copy; remove only inside a plan. |

| Catch-all utility | Split by domain capability or keep scoped with explicit owner. |

| Repeated prompt | Move stable prompt rule to versioned AI/resource doc; keep context examples separate. |

| Missing tests | Add characterization or manual validation before structural change. |

| Hidden dependency | Make dependency explicit or document order/contract before moving code. |

Cleanup Sequence

  1. Inventory the target area.
  2. Identify duplicates, large files, stale files, dead code, and catch-all modules.
  3. Rank findings by risk and user impact.
  4. Choose one small cleanup batch.
  5. Characterize current behavior.
  6. Apply the smallest extraction, deletion, move, or rename.
  7. Validate behavior.
  8. Record result in plan, changelog, and wiki if reusable.

Requested Removal

Use the Local scan for a button or field and Module for a modal, page or feature. The full rule, inventory and exceptions are in REFACTORING.md section 26. Plan block (prose is equally valid; a blank labelled field fails plan-removal):

## Removal sanitization

- Removed item and originating request:
- Terms searched (component, label, key, route, policy, text, style, test):
- Removed: interface / state / styles and texts / routes and services / policies / tests and scripts / documentation
- Exceptions with reason (shared, data, public contract, history) and deadline:
- Final search without an unjustified remaining hit:

Output Required

Create or fill a report using the code hygiene section of governance/TEMPLATE_REFACTORING.md when the scan is module-level or systemic. For local scans, add this compact block to the active plan:

## Code Hygiene Scan

- Skill loaded: `skills/code-hygiene-refactor/SKILL.md`
- Scan level: `local` / `module` / `systemic`
- Duplicate candidates:
- Large/monolithic candidates:
- Dead/stale candidates:
- Cleanup batch selected:
- Behavior preservation evidence:
- Deferred debt:

Exit Criteria

The cleanup is complete only when duplication, monolith risk, stale files, or dead code were reduced or explicitly deferred with evidence and a follow-up plan. A requested removal is complete only with its Removal sanitization block filled and a clean final search.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.