xiaohongshu
xiaohongshu
cc-refactoring-guidance
Guide safe refactoring with research-backed discipline and small-change rigor. Produce refactoring approach, step sequence, and risk assessment. Use when modifying existing code, improving structure without changing behavior, or deciding between refactor, rewrite, or fix-first. Triggers on: code ...
Full skill instructions
| Rule | Value | Source |
|---|---|---|
| Small change error rate | Peaks at 1-5 lines | Weinberg 1983 |
| First attempt success rate | <50% for any change | Yourdon 1986b |
| Review effect on 1-line changes | 55% -> 2% error rate | Freedman and Weinberg 1982 |
| Big refactoring | "Recipe for disaster" | Kent Beck |
Key Principles:
Critical: Error rates are PER CHANGE, not per person. Your 10-change success streak does not reduce probability on change 11. Each change is an independent event with >50% first-attempt error rate.
Definitions:
BEFORE starting any refactoring, identify target patterns:
| Search For | Why |
|---|---|
| Best examples of this pattern | What does "good" look like in this codebase? |
| Similar refactorings done before | How were they structured? |
| Module/directory conventions | What patterns dominate this area? |
| Recent improvements | What direction is the code evolving? |
Questions to answer:
If target pattern exists: Match it exactly. Copy naming, structure, style.
If no target pattern exists: You're establishing one. Consider:
See: pattern-reuse-gate.md for full gate protocol.
// BEFORE: Mixing concerns [ANTI-PATTERN]
// "I'm just cleaning while I fix the bug"
- Modified broken code
- Added refactoring changes
- Single commit with mixed purposes
// AFTER: Separated activities
1. Fix the bug (verify working)
2. Commit fix
3. Refactor working code
4. Commit refactoring
// BEFORE: Treating 1-line change casually [ANTI-PATTERN]
- Skip desk-check ("it's just one line")
- Skip review ("overkill for this")
- Skip testing ("obviously correct")
// AFTER: Small change rigor
- Desk-check even 1-line changes
- Get review (55% -> 2% error rate)
- Run regression tests
- Apply same rigor as large changes
// BEFORE: Adding comment to explain confusion [ANTI-PATTERN]
// Note: This calculates X by doing Y because of Z edge case
// which happens when A and B are both true and C is false
complicated_obscure_code();
// AFTER: Self-explanatory rewrite
clear_function_that_explains_itself();
Purpose: Guide refactoring decisions and safe refactoring process Triggers:
When production is down:
Emergency pressure doesn't change error statistics—it makes them WORSE due to stress. "Fix AND clean up" requests during outages: split them. Fix first, deploy, clean up later.
No automated tests:
No version control:
No reviewer available:
1. Does code currently work?
NO -> This is FIXING, not refactoring. Fix first.
YES -> Continue
2. Is the design fundamentally sound?
NO -> Consider REWRITING from scratch
YES -> Continue
3. Would changes touch >30% of module?
YES -> "Big refactoring" - consider rewrite
NO -> Proceed with incremental refactoring
Produces: Refactoring approach, step sequence, risk assessment Constraints:
Purpose: Transform code smells into clean code Triggers:
Input -> Output:
All of these mean: You're rationalizing. Follow the full rigor anyway.
If you mixed fix and refactor in one commit:
git reset --soft HEAD~1, separate changes, re-commit properly. Takes ~15 minutes.If you skipped review on a small change:
"It's too late" is almost never true. The discomfort of fixing violations is smaller than the debugging cost of bugs they cause.
| Excuse | Reality |
|---|---|
| "I'm just cleaning while I fix" | Fix first, then refactor. Separate commits. |
| "It's basically the same thing" | Refactoring = behavior-preserving. Fixing = behavior-changing. Different activities. |
| "It's just one line" | One-line changes have HIGHEST error rate. Apply full rigor. |
| "I don't need to test this" | >50% chance of error on first attempt at ANY change. |
| "Review would be overkill" | Reviews dropped 1-line change errors from 55% to 2%. |
| "I'll refactor it later" | Refactoring requires working code. Complete feature first, THEN refactor immediately. |
| "I can salvage this with refactoring" | Some code needs rewrite. Big refactoring is recipe for disaster. |
| "It'll save time to add this for later" | Speculative code usually wrong; slows current project. |
| "I already verified this manually" | Manual verification doesn't prevent >50% first-attempt error rate. Run automated tests. |
| "The tests pass, that's enough" | Tests verify behavior; review verifies the change itself. Both required. |
| "This change is isolated" | Even isolated 1-line changes have highest error rate. Isolation doesn't reduce rigor. |
| "It's an emergency" | Emergencies make errors MORE likely (stress). Fix only, deploy, refactor later. |
| "My last 5 changes worked" | Each change has INDEPENDENT >50% error rate. Past success doesn't reduce current odds. |
| "I already did it wrong but it works" | Working code doesn't validate process. Retroactively fix: soft-reset, separate, re-commit. |
| "No one's available to review" | Use 24h self-delay, rubber duck, or AI review. Something > nothing. |
| "We don't have tests" | Write characterization tests first, or document manual verification. Can't verify "behavior-preserving" blind. |
| After | Next |
|---|---|
| Refactoring complete | cc-control-flow-quality (CHECKER) |
| Structure changed | cc-routine-and-class-design (CHECKER) |
xiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience