Agent skill
Refactor/Slice File
Use this skill when a file exceeds ~350 lines (target) / approaches the 500-line hard cap, or has mixed responsibilities (UI + Logic + Types).
Install this agent skill to your Project
npx add-skill https://github.com/CheekyCodexConjurer/quant-lab/tree/main/skills/refactor_slice_file
SKILL.md
Refactor / Slice File
This skill applies the "Slicing" pattern to reduce complexity and context usage.
Triggers
- File > ~350 lines (target) or approaching the 500-line hard cap.
- User says "Refactor this large file".
AGENTS.mdMode E.
Recipe
Don't just move code. Split by responsibility.
1. Extract Types
- Create
{ComponentName}.types.ts - Move interfaces/enums there.
2. Extract Logic (Custom Hook)
- Create
use{ComponentName}.ts - Move
useEffect,useState, handlers, and complex logic there. - Return only what the UI needs (
{ data, handlers, state }).
3. Extract Sub-components
- Identify independent UI blocks (Modals, Lists, Cards).
- Move to separate files in the same folder or
components/subparts.
4. Reassemble
- The main file should look like a "View": mainly JSX/TSX with a single hook call.
- Validates that imports allow the app to run without circular dependencies.
Example Output Structure
/MyComponent
/index.tsx (The main export)
/MyComponent.tsx (The View)
/useMyComponent.ts (The Logic)
/MyComponent.types.ts (The Contract)
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
action_logger
Keep an audit trail of changes, commands, and verification.
size_guard
Enforce line budgets and rotate or split large context files.
analyze_repo_capabilities
Detect repo tooling and patterns, then record a dynamic manifest.
safety_validation
Validate changes against .agentignore before commit.
safe_refactor_migration
Plan and execute large refactors with shadow mode and rollback.
command_guard
Enforce .agentpolicy rules before executing commands.
Didn't find tool you were looking for?