[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7A92Z0XR8YWWHMS9BCGS5ZH":3,"skill-same:01M7A92Z0XR8YWWHMS9BCGS5ZH":46},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":29,"ownerDescription":30,"updatedAt":31,"install":32,"resources":45},"01M7A92Z0XR8YWWHMS9BCGS5ZH","refactor",null,"Use when refactoring existing code to improve readability or maintainability while preserving behavior.","aifgrouplaos\u002Fai-skills","aifgrouplaos","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F109958660?v=4","01M7A90G3NQ2B3FRB0WVTAK3ZY","AIF Group Laos","01M7A90G4N0QT4Z1FBB9EC9M92",0,"MIT","https:\u002F\u002Fgithub.com\u002Faifgrouplaos\u002Fai-skills\u002Fblob\u002Fmain\u002Fskills\u002Fengineering\u002Frefactor\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: refactor\ndescription: 'Use when refactoring existing code to improve readability or maintainability while preserving behavior.'\nlicense: MIT\n---\n\n# Refactor\n\nImprove existing code structure without changing its observable behavior. Prefer the smallest change that addresses a clear maintenance problem.\n\n## When to Use\n\n- Code is difficult to understand or safely change.\n- A function or module has multiple responsibilities.\n- Logic is duplicated, deeply nested, or coupled to the wrong object.\n- A requested feature is difficult because of the current structure.\n- The user asks to clean up or refactor existing code.\n\n## Refactoring Workflow\n\n1. **Understand the behavior.** Read the target code and its callers. Check relevant tests, types, exports, fixtures, and configuration. Identify the behavior and the specific maintenance problem.\n2. **Choose one change.** Make the smallest change that addresses that problem. Follow the codebase's conventions and reuse its existing helpers and patterns.\n3. **Verify.** Run relevant tests when verification is requested or repository instructions require them. If a non-trivial refactor lacks coverage, report that gap; add characterization tests when requested or required. If checks cannot run, say what remains unverified.\n4. **Review the result.** Inspect the diff for changes to return values, errors, ordering, side effects, public interfaces, and persisted or serialized data.\n5. **Finish cleanly.** Remove code only when it is confirmed unused. Update comments or docs only when the refactor makes them inaccurate.\n\nKeep the work in a recoverable version-control state and follow the repository's workflow. A separate branch or commit is useful when the project expects one; it is not a requirement for every refactor.\n\n## Core Rules\n\n- **Preserve behavior.** Do not change outputs, errors, side effects, ordering, or public contracts as part of a refactor. Treat bug fixes and feature changes as separate work.\n- **Work in small steps.** Make one focused change at a time.\n- **Keep it simple.** Prefer the least new code that solves the identified problem. Add an abstraction or design pattern only when it makes the current code easier to understand or change.\n- **Keep one purpose per unit.** Split functions or modules when their responsibilities are genuinely distinct, not to meet an arbitrary line limit.\n- **Name for intent.** Use clear names that fit the surrounding code.\n- **Remove repetition carefully.** Share logic when its meaning and behavior are the same. Similar-looking rules with different semantics should stay separate.\n- **Use types to express existing rules.** A type or value object may clarify a real domain concept. Do not use a refactor to add validation or change which inputs are accepted.\n- **Keep comments useful.** Prefer code that explains what it does. Keep comments that explain intent or a non-obvious constraint; remove stale or commented-out code.\n- **Limit the cleanup to the task.** Leave nearby code better when the focused change naturally does so; avoid unrelated cleanup.\n\n## Common Smells\n\n| Smell | Possible refactoring |\n| --- | --- |\n| Long function with distinct steps | Extract focused functions while keeping the same order and behavior. |\n| Repeated logic with the same meaning | Extract a shared helper. Keep different rules separate. |\n| Module or class with unrelated responsibilities | Move a responsibility to an existing or appropriately scoped module. |\n| Long parameter list | Group parameters only when they form a meaningful unit; update and inspect callers. |\n| Nested conditionals | Use guard clauses when they preserve the same checks, order, and outcomes. |\n| Logic that depends heavily on another object's data | Move the behavior toward the data owner when that improves cohesion and does not break boundaries. |\n| Primitive values representing a domain concept | Introduce a type or value object only when it captures a real invariant or improves safety. |\n| Unexplained literal values | Name values when the name adds meaning; ordinary obvious literals need no constant. |\n| Unused code | Remove it only after confirming it has no callers or required side effects. |\n\n### Guard Clause Example\n\nThese versions preserve the same checks and error results:\n\n```js\nfunction process(order) {\n  if (order) {\n    if (order.user) {\n      if (order.user.isActive) {\n        if (order.total > 0) return processOrder(order);\n        return { error: 'Invalid total' };\n      }\n      return { error: 'User inactive' };\n    }\n    return { error: 'No user' };\n  }\n  return { error: 'No order' };\n}\n```\n\n```js\nfunction process(order) {\n  if (!order) return { error: 'No order' };\n  if (!order.user) return { error: 'No user' };\n  if (!order.user.isActive) return { error: 'User inactive' };\n  if (!(order.total > 0)) return { error: 'Invalid total' };\n  return processOrder(order);\n}\n```\n\nThe total check uses `!(order.total > 0)` to preserve the original result for values such as `NaN`.\n\n## When to Defer a Refactor\n\n- There is no clear maintenance problem or expected benefit.\n- The code is stable and unlikely to change.\n- The change cannot be made safely within the available time.\n- Critical behavior lacks adequate protection and a safe characterization check is not practical.\n\n## Refactoring Operations\n\n| Operation | Use |\n| --- | --- |\n| Extract or inline function | Give a focused operation a clear name, or remove an unnecessary wrapper. |\n| Rename | Clarify intent; update and inspect all references. |\n| Extract class or module | Separate a responsibility with a clear boundary. |\n| Introduce parameter object | Group cohesive arguments; avoid wrapping unrelated values. |\n| Replace conditional with polymorphism | Use when there are real, growing variants and the result is simpler than the conditional. |\n| Replace type code with a type or enum | Make existing domain alternatives explicit without changing accepted values. |\n| Replace inheritance with delegation | Reduce unwanted coupling when behavior can remain the same. |\n\nDo not apply a pattern just because it appears in a catalog. A direct conditional or a small function is often clearer.\n\n## Completion Checklist\n\n- The original behavior and public contract are preserved.\n- The change addresses the identified problem and stays within scope.\n- Relevant callers and references still work.\n- Relevant checks pass, or the remaining verification gap is stated.\n- No unrelated code, new feature, or unnecessary abstraction was added.\n","# Refactor\n\nImprove existing code structure without changing its observable behavior. Prefer the smallest change that addresses a clear maintenance problem.\n\n## When to Use\n\n- Code is difficult to understand or safely change.\n- A function or module has multiple responsibilities.\n- Logic is duplicated, deeply nested, or coupled to the wrong object.\n- A requested feature is difficult because of the current structure.\n- The user asks to clean up or refactor existing code.\n\n## Refactoring Workflow\n\n1. **Understand the behavior.** Read the target code and its callers. Check relevant tests, types, exports, fixtures, and configuration. Identify the behavior and the specific maintenance problem.\n2. **Choose one change.** Make the smallest change that addresses that problem. Follow the codebase's conventions and reuse its existing helpers and patterns.\n3. **Verify.** Run relevant tests when verification is requested or repository instructions require them. If a non-trivial refactor lacks coverage, report that gap; add characterization tests when requested or required. If checks cannot run, say what remains unverified.\n4. **Review the result.** Inspect the diff for changes to return values, errors, ordering, side effects, public interfaces, and persisted or serialized data.\n5. **Finish cleanly.** Remove code only when it is confirmed unused. Update comments or docs only when the refactor makes them inaccurate.\n\nKeep the work in a recoverable version-control state and follow the repository's workflow. A separate branch or commit is useful when the project expects one; it is not a requirement for every refactor.\n\n## Core Rules\n\n- **Preserve behavior.** Do not change outputs, errors, side effects, ordering, or public contracts as part of a refactor. Treat bug fixes and feature changes as separate work.\n- **Work in small steps.** Make one focused change at a time.\n- **Keep it simple.** Prefer the least new code that solves the identified problem. Add an abstraction or design pattern only when it makes the current code easier to understand or change.\n- **Keep one purpose per unit.** Split functions or modules when their responsibilities are genuinely distinct, not to meet an arbitrary line limit.\n- **Name for intent.** Use clear names that fit the surrounding code.\n- **Remove repetition carefully.** Share logic when its meaning and behavior are the same. Similar-looking rules with different semantics should stay separate.\n- **Use types to express existing rules.** A type or value object may clarify a real domain concept. Do not use a refactor to add validation or change which inputs are accepted.\n- **Keep comments useful.** Prefer code that explains what it does. Keep comments that explain intent or a non-obvious constraint; remove stale or commented-out code.\n- **Limit the cleanup to the task.** Leave nearby code better when the focused change naturally does so; avoid unrelated cleanup.\n\n## Common Smells\n\n| Smell | Possible refactoring |\n| --- | --- |\n| Long function with distinct steps | Extract focused functions while keeping the same order and behavior. |\n| Repeated logic with the same meaning | Extract a shared helper. Keep different rules separate. |\n| Module or class with unrelated responsibilities | Move a responsibility to an existing or appropriately scoped module. |\n| Long parameter list | Group parameters only when they form a meaningful unit; update and inspect callers. |\n| Nested conditionals | Use guard clauses when they preserve the same checks, order, and outcomes. |\n| Logic that depends heavily on another object's data | Move the behavior toward the data owner when that improves cohesion and does not break boundaries. |\n| Primitive values representing a domain concept | Introduce a type or value object only when it captures a real invariant or improves safety. |\n| Unexplained literal values | Name values when the name adds meaning; ordinary obvious literals need no constant. |\n| Unused code | Remove it only after confirming it has no callers or required side effects. |\n\n### Guard Clause Example\n\nThese versions preserve the same checks and error results:\n\n```js\nfunction process(order) {\n  if (order) {\n    if (order.user) {\n      if (order.user.isActive) {\n        if (order.total > 0) return processOrder(order);\n        return { error: 'Invalid total' };\n      }\n      return { error: 'User inactive' };\n    }\n    return { error: 'No user' };\n  }\n  return { error: 'No order' };\n}\n```\n\n```js\nfunction process(order) {\n  if (!order) return { error: 'No order' };\n  if (!order.user) return { error: 'No user' };\n  if (!order.user.isActive) return { error: 'User inactive' };\n  if (!(order.total > 0)) return { error: 'Invalid total' };\n  return processOrder(order);\n}\n```\n\nThe total check uses `!(order.total > 0)` to preserve the original result for values such as `NaN`.\n\n## When to Defer a Refactor\n\n- There is no clear maintenance problem or expected benefit.\n- The code is stable and unlikely to change.\n- The change cannot be made safely within the available time.\n- Critical behavior lacks adequate protection and a safe characterization check is not practical.\n\n## Refactoring Operations\n\n| Operation | Use |\n| --- | --- |\n| Extract or inline function | Give a focused operation a clear name, or remove an unnecessary wrapper. |\n| Rename | Clarify intent; update and inspect all references. |\n| Extract class or module | Separate a responsibility with a clear boundary. |\n| Introduce parameter object | Group cohesive arguments; avoid wrapping unrelated values. |\n| Replace conditional with polymorphism | Use when there are real, growing variants and the result is simpler than the conditional. |\n| Replace type code with a type or enum | Make existing domain alternatives explicit without changing accepted values. |\n| Replace inheritance with delegation | Reduce unwanted coupling when behavior can remain the same. |\n\nDo not apply a pattern just because it appears in a catalog. A direct conditional or a small function is often clearer.\n\n## Completion Checklist\n\n- The original behavior and public contract are preserved.\n- The change addresses the identified problem and stays within scope.\n- Relevant callers and references still work.\n- Relevant checks pass, or the remaining verification gap is stated.\n- No unrelated code, new feature, or unnecessary abstraction was added.\n",{"name":5,"license":15,"description":7},"main","755978d235198b4e44bb62d528d0411d3b955bcf","skills\u002Fengineering\u002Frefactor","https:\u002F\u002Fgithub.com\u002Faifgrouplaos\u002Fai-skills","https:\u002F\u002Fgithub.com\u002Faifgrouplaos","https:\u002F\u002Fwww.aifgrouplaos.com\u002F","AIF group Laos","2026-10-29 14:49:38",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add aifgrouplaos\u002Fai-skills --skill refactor",{"tool":38,"command":39},"bunx","bunx skills add aifgrouplaos\u002Fai-skills --skill refactor",{"tool":41,"command":42},"pnpm","pnpm dlx skills add aifgrouplaos\u002Fai-skills --skill refactor","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Faifgrouplaos\u002Fai-skills\u002Fblob\u002Fmain\u002Fskills\u002Fengineering\u002Frefactor\u002FSKILL.md",true,[],[]]