{"id":"08208d05-a920-4af3-a7ce-88e39157f3ed","shortId":"wwS2Vx","kind":"skill","title":"Refactor Planner","tagline":"Creates a safe, step-by-step plan to refactor messy code without breaking existing behavior.","description":"# Refactor Planner\n\n## What this skill does\n\nThis skill directs the agent to analyze a block of code (or an entire module) and produce an ordered, safe refactoring plan. Rather than rewriting everything at once, it breaks the work into small, reversible steps — each one leaving the tests green and the behavior unchanged. It identifies code smells, maps dependencies, flags high-risk areas, and sequences the changes so you can ship incrementally without introducing regressions.\n\nUse this when you have messy, hard-to-understand code that works but needs cleaning up before you can safely add features.\n\n## How to use\n\n### Claude Code / Cline\n\nCopy this file to `.agents/skills/refactor-planner/SKILL.md` in your project root.\n\nThen ask the agent:\n- *\"Use the Refactor Planner skill on `src/utils/dataProcessor.ts`.\"*\n- *\"Plan a safe refactor of this function using the Refactor Planner skill.\"*\n\nPaste in the code you want refactored, or point to a file path.\n\n### Cursor\n\nAdd the \"Prompt / Instructions\" section below to your `.cursorrules` file, or paste it directly into the Cursor AI pane before sharing the code you want refactored.\n\n### Codex\n\nPaste the target code into the chat along with the instructions from the section below. For large files, include the full file plus any files that import from it so Codex can map dependencies.\n\n## The Prompt / Instructions for the Agent\n\nWhen asked to plan a refactor, follow these steps precisely:\n\n1. **Read the code thoroughly.** If a file path is given, read the full file. Also read any files that import from it or that it imports from, so you understand the dependency graph.\n\n2. **Identify code smells.** Look for:\n   - Functions longer than 40 lines\n   - Deeply nested conditionals (more than 3 levels)\n   - Duplicated logic (copy-paste code)\n   - Magic numbers and hardcoded strings\n   - God objects or functions that do too many things\n   - Inconsistent naming conventions\n   - Mutable shared state\n   - Missing or misleading comments\n   - Dead code (unreachable or unused)\n\n3. **Map dependencies.** For each problematic section, note:\n   - What calls it (callers)\n   - What it calls (callees)\n   - What data it reads or mutates\n   - Whether it has test coverage\n\n4. **Assess risk for each change.** Label every planned step as:\n   - **Low risk** — pure rename, extract with no logic change, add a comment\n   - **Medium risk** — restructure logic that has test coverage\n   - **High risk** — change with no tests, touches shared state, or modifies a public API\n\n5. **Generate the ordered refactoring plan.** Each step must:\n   - Be small enough to do in a single commit\n   - Leave the code in a working state after it is applied\n   - Be described clearly so a developer can execute it manually\n   - Reference the specific function, class, or line range it affects\n   - Come with a one-line \"how to verify this step didn't break anything\"\n\n6. **Format the output as follows:**\n\n```\n## Code Smells Found\n- [Smell type]: [Description] — [Location]\n...\n\n## Dependency Map\n- `functionName` is called by: X, Y, Z\n- `functionName` depends on: A, B\n...\n\n## Refactoring Plan\n\n### Step 1 — [Title] [Risk: Low/Medium/High]\n**What:** [What to change]\n**Why:** [Which smell this addresses]\n**How:** [Concrete action, e.g., \"Extract lines 45–67 into a new function called `validateInput`\"]\n**Verify:** [How to confirm nothing broke, e.g., \"Run `npm test` — all existing tests should pass\"]\n\n### Step 2 — ...\n...\n\n## High-Risk Flags\n[List any steps that need special attention, tests to write first, or API surface changes that require coordination]\n```\n\n7. **Do not rewrite the code yet.** The output is a plan only. If the user then asks you to execute a specific step, do it one step at a time.\n\n## Example\n\n**Input to Agent:**\n> \"Use the Refactor Planner skill on this function:\n>\n> ```ts\n> function process(data: any) {\n>   let result = [];\n>   for (let i = 0; i < data.length; i++) {\n>     if (data[i].type === 'A') {\n>       if (data[i].value > 100) {\n>         if (data[i].active) {\n>           result.push({ id: data[i].id, score: data[i].value * 1.5 });\n>         }\n>       }\n>     } else if (data[i].type === 'B') {\n>       if (data[i].value > 50) {\n>         result.push({ id: data[i].id, score: data[i].value * 1.2 });\n>       }\n>     }\n>   }\n>   return result;\n> }\n> ```\"\n\n**Output from Agent:**\n> ## Code Smells Found\n> - Deep nesting: Triple-nested conditionals make the logic hard to follow — lines 3–13\n> - Magic numbers: `100`, `1.5`, `50`, `1.2` have no named meaning — lines 5, 8, 12, 13\n> - Loose typing: `data: any` loses all type safety — line 1\n>\n> ## Refactoring Plan\n>\n> ### Step 1 — Name the magic numbers [Risk: Low]\n> **What:** Extract `100`, `1.5`, `50`, `1.2` into named constants at the top of the file.\n> **Why:** Eliminates magic numbers, makes thresholds searchable.\n> **How:** Add `const TYPE_A_THRESHOLD = 100`, `const TYPE_A_MULTIPLIER = 1.5`, etc.\n> **Verify:** Run existing tests — output should be identical.\n>\n> ### Step 2 — Add types [Risk: Low]\n> **What:** Define an `Item` interface and replace `any`.\n> **Why:** Prevents silent bugs from misshapen input.\n> **How:** `interface Item { id: string; type: 'A' | 'B'; value: number; active?: boolean }`\n> **Verify:** TypeScript should compile with no new errors.\n>\n> ### Step 3 — Extract per-type handlers [Risk: Medium]\n> **What:** Move the type A and type B branches into `processTypeA(item)` and `processTypeB(item)`.\n> **Why:** Eliminates deep nesting, makes each branch independently testable.\n> **How:** Extract the inner `if` blocks into separate functions that return `{ id, score } | null`.\n> **Verify:** Run tests; add a unit test for each new function before extracting.","tags":["refactor","planner","openagentskills","notysoty","agent-skills","claude","claude-code","claude-skills","cline","cursor","llm","llm-skills"],"capabilities":["skill","source-notysoty","skill-refactor-planner","topic-agent-skills","topic-claude","topic-claude-code","topic-claude-skills","topic-cline","topic-cursor","topic-llm","topic-llm-skills","topic-skills"],"categories":["openagentskills"],"synonyms":[],"warnings":[],"endpointUrl":"https://skills.sh/Notysoty/openagentskills/refactor-planner","protocol":"skill","transport":"skills-sh","auth":{"type":"none","details":{"cli":"npx skills add Notysoty/openagentskills","source_repo":"https://github.com/Notysoty/openagentskills","install_from":"skills.sh"}},"qualityScore":"0.454","qualityRationale":"deterministic score 0.45 from registry signals: · indexed on github topic:agent-skills · 8 github stars · SKILL.md body (5,721 chars)","verified":false,"liveness":"unknown","lastLivenessCheck":null,"agentReviews":{"count":0,"score_avg":null,"cost_usd_avg":null,"success_rate":null,"latency_p50_ms":null,"narrative_summary":null,"summary_updated_at":null},"enrichmentModel":"deterministic:skill-github:v1","enrichmentVersion":1,"enrichedAt":"2026-05-18T19:13:24.124Z","embedding":null,"createdAt":"2026-05-18T13:20:45.814Z","updatedAt":"2026-05-18T19:13:24.124Z","lastSeenAt":"2026-05-18T19:13:24.124Z","tsv":"'0':618 '1':246,499,714,718 '1.2':666,695,730 '1.5':645,693,728,758 '100':631,692,727,753 '12':703 '13':689,704 '2':280,542,769 '3':296,333,688,810 '4':360 '40':289 '45':518 '5':405,701 '50':656,694,729 '6':469 '67':519 '7':565 '8':702 'action':514 'activ':635,799 'add':115,169,380,748,770,859 'address':511 'affect':453 'agent':29,135,235,599,671 'agents/skills/refactor-planner/skill.md':127 'ai':186 'along':203 'also':261 'analyz':31 'anyth':468 'api':404,559 'appli':433 'area':81 'ask':133,237,582 'assess':361 'attent':553 'b':495,651,796,825 'behavior':18,69 'block':33,847 'boolean':800 'branch':826,839 'break':16,54,467 'broke':531 'bug':785 'call':342,347,486,524 'calle':348 'caller':344 'chang':85,365,379,393,506,561 'chat':202 'class':448 'claud':120 'clean':109 'clear':436 'cline':122 'code':14,35,73,104,121,158,191,199,249,282,303,329,425,475,570,672 'codex':195,226 'come':454 'comment':327,382 'commit':422 'compil':804 'concret':513 'condit':293,680 'confirm':529 'const':749,754 'constant':733 'convent':320 'coordin':564 'copi':123,301 'copy-past':300 'coverag':359,390 'creat':3 'cursor':168,185 'cursorrul':177 'data':350,611,623,628,633,638,642,648,653,659,663,707 'data.length':620 'dead':328 'deep':675,835 'deepli':291 'defin':775 'depend':76,229,278,335,482,492 'describ':435 'descript':480 'develop':439 'didn':465 'direct':27,182 'duplic':298 'e.g':515,532 'elimin':741,834 'els':646 'enough':416 'entir':38 'error':808 'etc':759 'everi':367 'everyth':50 'exampl':596 'execut':441,585 'exist':17,537,762 'extract':375,516,726,811,843,868 'featur':116 'file':125,166,178,213,217,220,253,260,264,739 'first':557 'flag':77,546 'follow':242,474,686 'format':470 'found':477,674 'full':216,259 'function':149,286,312,447,523,607,609,850,866 'functionnam':484,491 'generat':406 'given':256 'god':309 'graph':279 'green':66 'handler':815 'hard':101,684 'hard-to-understand':100 'hardcod':307 'high':79,391,544 'high-risk':78,543 'id':637,640,658,661,792,853 'ident':767 'identifi':72,281 'import':222,266,272 'includ':214 'inconsist':318 'increment':90 'independ':840 'inner':845 'input':597,788 'instruct':172,206,232 'interfac':778,790 'introduc':92 'item':777,791,829,832 'label':366 'larg':212 'leav':63,423 'let':613,616 'level':297 'line':290,450,459,517,687,700,713 'list':547 'locat':481 'logic':299,378,386,683 'longer':287 'look':284 'loos':705 'lose':709 'low':371,724,773 'low/medium/high':502 'magic':304,690,721,742 'make':681,744,837 'mani':316 'manual':443 'map':75,228,334,483 'mean':699 'medium':383,817 'messi':13,99 'mislead':326 'miss':324 'misshapen':787 'modifi':401 'modul':39 'move':819 'multipli':757 'must':413 'mutabl':321 'mutat':354 'name':319,698,719,732 'need':108,551 'nest':292,676,679,836 'new':522,807,865 'note':340 'noth':530 'npm':534 'null':855 'number':305,691,722,743,798 'object':310 'one':62,458,591 'one-lin':457 'order':43,408 'output':472,573,669,764 'pane':187 'pass':540 'past':155,180,196,302 'path':167,254 'per':813 'per-typ':812 'plan':10,46,143,239,368,410,497,576,716 'planner':2,20,139,153,603 'plus':218 'point':163 'precis':245 'prevent':783 'problemat':338 'process':610 'processtypea':828 'processtypeb':831 'produc':41 'project':130 'prompt':171,231 'public':403 'pure':373 'rang':451 'rather':47 'read':247,257,262,352 'refactor':1,12,19,45,138,146,152,161,194,241,409,496,602,715 'refer':444 'regress':93 'renam':374 'replac':780 'requir':563 'restructur':385 'result':614,668 'result.push':636,657 'return':667,852 'revers':59 'rewrit':49,568 'risk':80,362,372,384,392,501,545,723,772,816 'root':131 'run':533,761,857 'safe':5,44,114,145 'safeti':712 'score':641,662,854 'searchabl':746 'section':173,209,339 'separ':849 'sequenc':83 'share':189,322,398 'ship':89 'silent':784 'singl':421 'skill':23,26,140,154,604 'skill-refactor-planner' 'small':58,415 'smell':74,283,476,478,509,673 'source-notysoty' 'special':552 'specif':446,587 'src/utils/dataprocessor.ts':142 'state':323,399,429 'step':7,9,60,244,369,412,464,498,541,549,588,592,717,768,809 'step-by-step':6 'string':308,793 'surfac':560 'target':198 'test':65,358,389,396,535,538,554,763,858,862 'testabl':841 'thing':317 'thorough':250 'threshold':745,752 'time':595 'titl':500 'top':736 'topic-agent-skills' 'topic-claude' 'topic-claude-code' 'topic-claude-skills' 'topic-cline' 'topic-cursor' 'topic-llm' 'topic-llm-skills' 'topic-skills' 'touch':397 'tripl':678 'triple-nest':677 'ts':608 'type':479,625,650,706,711,750,755,771,794,814,821,824 'typescript':802 'unchang':70 'understand':103,276 'unit':861 'unreach':330 'unus':332 'use':94,119,136,150,600 'user':580 'validateinput':525 'valu':630,644,655,665,797 'verifi':462,526,760,801,856 'want':160,193 'whether':355 'without':15,91 'work':56,106,428 'write':556 'x':488 'y':489 'yet':571 'z':490","prices":[{"id":"988e74a7-9c51-4763-a329-5c5470db3d62","listingId":"08208d05-a920-4af3-a7ce-88e39157f3ed","amountUsd":"0","unit":"free","nativeCurrency":null,"nativeAmount":null,"chain":null,"payTo":null,"paymentMethod":"skill-free","isPrimary":true,"details":{"org":"Notysoty","category":"openagentskills","install_from":"skills.sh"},"createdAt":"2026-05-18T13:20:45.814Z"}],"sources":[{"listingId":"08208d05-a920-4af3-a7ce-88e39157f3ed","source":"github","sourceId":"Notysoty/openagentskills/refactor-planner","sourceUrl":"https://github.com/Notysoty/openagentskills/tree/main/skills/refactor-planner","isPrimary":false,"firstSeenAt":"2026-05-18T13:20:45.814Z","lastSeenAt":"2026-05-18T19:13:24.124Z"}],"details":{"listingId":"08208d05-a920-4af3-a7ce-88e39157f3ed","quickStartSnippet":null,"exampleRequest":null,"exampleResponse":null,"schema":null,"openapiUrl":null,"agentsTxtUrl":null,"citations":[],"useCases":[],"bestFor":[],"notFor":[],"kindDetails":{"org":"Notysoty","slug":"refactor-planner","github":{"repo":"Notysoty/openagentskills","stars":8,"topics":["agent-skills","claude","claude-code","claude-skills","cline","cursor","llm","llm-skills","skills"],"license":"mit","html_url":"https://github.com/Notysoty/openagentskills","pushed_at":"2026-03-28T06:50:19Z","description":"A  community-driven library of reusable AI agent skills for Claude Code, Cursor, Codex, Cline, and more.","skill_md_sha":"e5abeafcbe1129c9b380eb0765933cb6aa9320c9","skill_md_path":"skills/refactor-planner/SKILL.md","default_branch":"main","skill_tree_url":"https://github.com/Notysoty/openagentskills/tree/main/skills/refactor-planner"},"layout":"multi","source":"github","category":"openagentskills","frontmatter":{"name":"Refactor Planner","description":"Creates a safe, step-by-step plan to refactor messy code without breaking existing behavior."},"skills_sh_url":"https://skills.sh/Notysoty/openagentskills/refactor-planner"},"updatedAt":"2026-05-18T19:13:24.124Z"}}