{"success":true,"name":"decide-refactor-or-leave-it-using-future-cost-not-discomfort","description":"Looking at working but ugly code and unsure whether to refactor it","category":"ai-brimind","path":"ai-brimind/decide-refactor-or-leave-it-using-future-cost-not-discomfort/SKILL.md","file":"SKILL.md","content":"---\nname: decide-refactor-or-leave-it-using-future-cost-not-discomfort\ndescription: \"Looking at working but ugly code and unsure whether to refactor it\"\n---\n\n# Decide Refactor or Leave It Using Future Cost, Not Discomfort\n\n## When to use\nLooking at working but ugly code and unsure whether to refactor it\n\n## Example request\nUgly function nobody has touched in a year and no changes planned → discomfort alone doesn't justify risk; leave it, note it; the concept is refactor ROI. The file you must modify this week is a 900-line tangle → the change you're about to make will fight the structure; refactor the path you need first; the concept is refactor-before-feature (boy scout on the touched path). Same pricing logic copy-pasted in 4 places and a pricing change is coming → one bug becomes four; extract now; the concept is duplication with active change pressure. Mid-feature you notice unrelated messy code → widening the change doubles the risk; log it as a task, finish the feature; the concept is scope discipline.\n\n## Instructions\nAct as an economist of code who spends refactoring effort only where it pays. When code feels wrong, do not act on the feeling — run the decision test: (1) Is this code on an ACTIVE path — will it be changed, extended, or debugged soon (this task, this milestone)? (2) What is the cost of leaving it — count concretely: how many places must change together, how long it takes to understand, how often bugs come from here? (3) What is the cost and risk of refactoring — is the behavior protected (tests, a written scenario to re-run), and can it be done in small safe steps? Then decide: active path + real recurring cost + protectable behavior = refactor NOW, but only the path you touch, in small steps, verifying behavior is unchanged after each step (refactor = same behavior, better structure — never mix it with adding features in one move). Not on an active path, or cost is only aesthetic = LEAVE IT, and record it honestly in the project's .md debt list with what would trigger revisiting it. If you can't protect the behavior before restructuring, that's your first task, or ask the project owner for the time to do it. Always state your decision and its reasoning in one sentence — 'refactoring because 3 upcoming changes hit this file' or 'leaving it: works, untouched, isolated' — so the choice is a judgment, not a mood.\n\n## Metadata\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #160\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}