{
  "version": "act 1.0.17",
  "slug": "refactoring",
  "name": "refactoring",
  "description": "Perform semantic code refactoring using AST-aware tools. Use when renaming symbols, extracting functions or variables, inlining code, moving symbols between files, organizing imports, or any code transformation that must update all references. Supports preview mode and undo. Works across TypeScript, Python, Rust, Go, and 14 more languages.",
  "url": "https://act101.ai/docs/skills/refactoring",
  "body_md": "# Refactoring with act\n\n6 MCP refactor tools with preview mode and undo/redo. All tools are AST-based \u2014 no LSP required.\n\n## Start Here\n\n```\nstatus()\n```\n\n## Refactor Tools\n\n### rename\nRename a symbol and update all references across the codebase.\n```\nrename(file=\"src/user.ts\", old_name=\"getData\", new_name=\"fetchData\", preview=true)\n```\n\n### extract_function\nExtract a code range into a new named function.\n```\nextract_function(file=\"src/utils.ts\", new_name=\"validateInput\", start_line=10, start_column=1, end_line=20, end_column=50, preview=true)\n```\n\n### extract_variable\nExtract an expression into a named variable.\n```\nextract_variable(file=\"src/calc.ts\", new_name=\"basePrice\", start_line=15, start_column=5, end_line=15, end_column=40, preview=true)\n```\n\n### inline\nInline a variable or function at all usage sites.\n```\ninline(file=\"src/utils.ts\", symbol=\"tempResult\", preview=true)\n```\n\n### move_symbol\nMove a symbol to a different file, updating all imports.\n```\nmove_symbol(file=\"src/models.ts\", symbol=\"UserService\", destination=\"src/services/user.ts\", preview=true)\n```\n\n### import_organize\nSort and clean up imports in a file.\n```\nimport_organize(file=\"src/main.ts\", preview=true)\n```\n\n## Workflow\n\n1. **Preview first** \u2014 Set `preview=true` (or omit \u2014 default is false, so always set it explicitly for safety)\n2. **Review the diff** \u2014 Check the returned `FileChange[]` array\n3. **Apply** \u2014 Re-run with `preview=false`\n4. **Verify** \u2014 Run `diagnostics(file=\"...\")` to check for introduced errors\n5. **Undo if needed** \u2014 `history_undo(preview=true)` then `history_undo()`\n\n## History (Undo/Redo)\n\n```\nhistory_list(limit=10)   # See recent operations\nhistory_undo(count=1)    # Undo last operation\nhistory_redo(count=1)    # Redo undone operation\n```\n\n## Safety Rules\n\n1. **Always preview before applying** \u2014 especially for rename and move_symbol which affect multiple files\n2. **Run diagnostics after each batch of refactors** \u2014 catch introduced errors immediately\n3. **Batch independent operations in parallel** \u2014 operations that touch different symbols/files can run concurrently. This is the primary efficiency advantage of act. Only sequence operations that depend on each other's output.\n4. **Undo immediately if diagnostics show new errors** \u2014 don't stack more refactors on top of a broken state\n5. **Don't create files manually** \u2014 operations like `move_symbol`, `extract-class`, and `extract-interface` create destination files automatically. Never write a file just so an operation can target it.\n\n## Compound Refactoring\n\nComplex refactors often require sequences of operations. See [compound-sequences.md](references/compound-sequences.md) for patterns like extract-then-rename, move-then-organize, and decompose-god-class.\n\n## Code Generation\n\nAfter structural refactoring (extract class, extract interface), the new type often needs boilerplate. See the **code-generation** skill for batch generation of constructors, accessors, equals, hash, serialization, and other derived methods.\n\n## Full Operation Catalog\n\nThe `act` CLI supports ~160 refactor operations beyond the 6 MCP tools (generate-constructor, convert-async, wrap-try-catch, etc). See [operation-catalog.md](references/operation-catalog.md) for the complete list organized by category. These are available via the CLI but not yet exposed as individual MCP tools.\n\n## Error Recovery\n\nSee [error-recovery.md](references/error-recovery.md) for handling common failures."
}