ic-refactor
Refactor IC10 code for clarity and structure. Use when user wants to reorganize code, apply design patterns, improve naming, or make code more maintainable without changing functionality.
When & Why to Use This Skill
This Claude skill provides professional-grade refactoring for IC10 code, focusing on enhancing readability, structure, and long-term maintainability. It intelligently applies design patterns like state machines and PID loops while ensuring functional parity, making complex Stationeers scripts easier to understand, manage, and extend.
Use Cases
- Improving Readability: Automatically replacing generic registers (r0-r15) and device pins (d0-d5) with descriptive aliases to make the logic self-documenting.
- Structural Reorganization: Grouping related logic into clear sections with headers, such as separating initialization, main loops, and subroutines for better navigation.
- Pattern Implementation: Converting manual conditional logic into robust design patterns like state machines for multi-phase processes or hysteresis for threshold control.
- Code Standardization: Extracting hardcoded 'magic numbers' into named constants and adding professional documentation to clarify complex logic flows.
| name | ic-refactor |
|---|---|
| description | Refactor IC10 code for clarity and structure. Use when user wants to reorganize code, apply design patterns, improve naming, or make code more maintainable without changing functionality. |
IC10 Code Refactoring
Restructure IC10 code for better clarity, organization, and maintainability.
When to Use
This skill is for restructuring code, not optimizing it:
| User Request | Use This Skill? |
|---|---|
| "Refactor this code" | ✅ Yes |
| "Make this more readable" | ✅ Yes |
| "Reorganize this script" | ✅ Yes |
| "Apply state machine pattern" | ✅ Yes |
| "Extract constants" | ✅ Yes |
| "Reduce line count" | ❌ Use ic-optimize |
| "Make this faster" | ❌ Use ic-optimize |
| "Fix this bug" | ❌ Use ic-debug |
Workflow
1. Analysis Phase
Use Task tool to spawn in parallel:
code-analyzer- Understand current structure and identify issuespattern-finder- Find applicable patterns from examples
2. Refactoring Phase
Use Task tool to spawn:
code-refactorer- Apply refactoring with analysis context
Provide the refactorer with:
- Original code
- Analysis results
- User's specific requests (if any)
- Applicable patterns found
3. Documentation Phase (Optional)
If code needs documentation after refactoring:
code-documenter- Add/update comments and headers
Refactoring Types
Structure Refactoring
- Organize code into clear sections (aliases, constants, main loop)
- Add section headers with comments
- Group related operations together
Naming Refactoring
- Replace d0-d5 with meaningful aliases
- Replace r0-r15 with descriptive names where appropriate
- Extract magic numbers to named defines
Pattern Application
- State machine for multi-phase processes
- Hysteresis for threshold control
- PID for smooth control loops
- Subroutines for repeated logic
Code Clarity
- Split complex conditions into steps
- Add intermediate variables for clarity
- Improve comment quality
Instructions
When user requests IC10 refactoring:
Identify refactoring type
- Is it structure, naming, pattern, or general cleanup?
- Note any specific user requests
Launch analysis agents (parallel)
- code-analyzer: Current structure assessment
- pattern-finder: Applicable patterns
Launch refactorer with context
- Include analysis results
- Specify user's focus areas
- Request explanation of changes
Present results
- Show before/after comparison
- Explain each change made
- Highlight patterns applied
Offer documentation if needed
- Ask if user wants additional comments
- Can run code-documenter as follow-up
Example Triggers
- "Refactor this for clarity"
- "Reorganize this code"
- "Make this more readable"
- "Apply state machine pattern"
- "Extract constants from this"
- "Improve the structure"
- "Clean up this script"
- "Add proper aliases"
- "Convert to hysteresis pattern"
Key Principles
- Never change functionality - Refactoring preserves behavior
- Clarity over brevity - May add lines for readability
- Meaningful names - All aliases should be descriptive
- Pattern where appropriate - Don't force patterns unnecessarily
- Explain changes - User should understand what changed and why