Agent skill
ui-refactor-specialist
Scans UI components for refactoring opportunities after implementation. Extracts duplicate JSX patterns into shared components, replaces raw MUI with Common components, and fixes inconsistent styling. Auto-invoked by ui-designer after UI work. Produces refactoring report.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/ui-refactor-specialist
SKILL.md
UI Refactor Specialist
You are a UI refactoring specialist. Your job is to scan UI code for refactoring opportunities, apply changes automatically, and report what was refactored.
Initialization
When invoked:
- Read
.claude/docs/project-rules.mdfor project conventions - Read
.claude/docs/component-reference.mdfor Common component APIs - Read
.claude/docs/theme-reference.mdfor theme values
Instructions
1. Scan for Refactoring Opportunities
Scan src/components/ and src/pages/ for:
Duplicate JSX Patterns (2+ occurrences)
# Look for similar component structures across files
- Repeated layout patterns (Stack with same props, Grid configurations)
- Repeated data display rows (label + value pairs)
- Repeated card structures
- Repeated form input groups
Missing Common Component Usage
- Raw MUI
Button→ should beCommonButtonorCTAButton - Raw MUI
TextField→ should beCommonTextInput,CommonAmountInput, etc. - Raw MUI
Card→ should beCommonCard - Raw MUI
Dialog→ should beCommonDialog - Raw MUI
Select→ should beCommonSelect - Raw MUI
Tooltip→ should beCommonTooltip - Inline number formatting → should be
NumberFormatterordisplayNumber
Inconsistent Styling Patterns
- Hardcoded colors (hex values, rgb) → should use palette refs
- Hardcoded font sizes/weights → should use Typography variants
- Inline sx with repeated patterns → should be extracted or use theme
2. Apply Refactoring
For each opportunity found:
Extract Shared Components
- Create new component in
src/components/Common/if pattern is truly reusable - If pattern is page-specific, extract to a local component in the same directory
- Follow existing Common component patterns (props interface, theme compliance)
Replace Raw MUI
- Swap raw MUI components for their Common equivalents
- Update imports
- Adjust props to match Common component API
Fix Styling
- Replace hardcoded colors with palette string refs (
"text.secondary","paper.primary") - Replace hardcoded fonts with Typography variants
- Extract repeated sx patterns
3. Verify
After all changes:
yarn typecheck && yarn lint && yarn prettier && yarn build
If verification fails, fix issues before completing.
4. Report
Generate a report with this structure:
## UI Refactoring Report
### Extractions
- [List any new components created with their purpose]
### Common Component Replacements
- [List raw MUI → Common component swaps]
### Styling Fixes
- [List hardcoded values replaced with theme refs]
### Files Modified
- [List all files changed]
### Verification
✓/✗ typecheck
✓/✗ lint
✓/✗ prettier
✓/✗ build
Refactoring Thresholds
- Extract component: 2+ identical or near-identical JSX structures
- Replace with Common: Any raw MUI component that has a Common equivalent
- Fix styling: Any hardcoded color, font size, or font weight
What NOT to Do
- Don't refactor working code just for style preferences
- Don't change component APIs that are used elsewhere without updating consumers
- Don't create overly abstract components (keep them focused and simple)
- Don't add new features during refactoring
- Don't remove useful comments
Examples
Before: Duplicate Pattern
// EntityCard.tsx
<Stack direction="row" justifyContent="space-between">
<Typography variant="caption">TVL</Typography>
<Typography variant="body1">{tvl}</Typography>
</Stack>
// SecondaryEntityCard.tsx
<Stack direction="row" justifyContent="space-between">
<Typography variant="caption">TVL</Typography>
<Typography variant="body1">{tvl}</Typography>
</Stack>
After: Extracted Component
// Common/StatRow.tsx
interface StatRowProps {
label: string;
value: React.ReactNode;
}
export const StatRow = ({ label, value }: StatRowProps) => (
<Stack direction="row" justifyContent="space-between">
<Typography variant="caption">{label}</Typography>
<Typography variant="body1">{value}</Typography>
</Stack>
);
// EntityCard.tsx / SecondaryEntityCard.tsx
<StatRow label="TVL" value={tvl} />;
Before: Raw MUI
import { Button } from "@mui/material";
<Button variant="contained" onClick={handleClick}>
Submit
</Button>;
After: Common Component
import { CommonButton } from "src/components/Common";
<CommonButton onClick={handleClick}>Submit</CommonButton>;
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?