@refactor-tool/cli
v0.1.1
Published
AI-powered refactoring tool for frontend projects with OpenSpec integration
Downloads
214
Maintainers
Readme
Refactor Tool
AI-powered refactoring tool for frontend projects with OpenSpec integration.
Overview
Refactor Tool helps you refactor frontend projects ([email protected] + TypeScript + antd@4) using independent refactor capabilities. Each capability can be executed independently without requiring other capabilities to complete first.
Available Capabilities:
- directory-structure - Analyze and refactor project/component directory structure
- component-design - Analyze component design, props, and reusability
- code-style - Analyze code style issues (ESLint, Stylelint, TypeScript, JS→TS conversion)
- business-logic - Analyze business logic, state management, and API patterns
- styled-jsx-to-css-module - Convert styled-jsx to CSS Module format
Features
- ✅ Independent capabilities - Execute any refactor capability independently
- ✅ Optional stage workflow - Use
--stage-modefor stage-based workflow if preferred - ✅ OpenSpec integration - Manage refactoring proposals with OpenSpec
- ✅ Cursor IDE support - Integrated commands and skills for Cursor
- ✅ Capability dependencies - Optional dependency checking with warnings (non-blocking)
- ✅ Batch analysis - Support for large projects with incremental analysis
Installation
npm install -g @refactor-tool/cliQuick Start
- Initialize the tool in your project:
refactor initThis creates:
refactor/directory with OpenSpec structure- 4 refactoring skills in
.cursor/skills/ - Cursor commands in
.cursor/commands/
- Start refactoring:
- Use
/refactor-tool-refactorcommand in Cursor to analyze your project - Review and apply proposals using
/refactor-tool-apply - Archive completed proposals using
/refactor-tool-archive
- Use
CLI Commands
refactor init [path]- Initialize refactor tool in your projectrefactor capabilities- List all available refactor capabilitiesrefactor list- List all active refactoring proposalsrefactor show [proposal-id]- Show a refactoring proposalrefactor archive [proposal-id]- Archive a completed proposalrefactor update [path]- Update refactor tool instruction files
Cursor Commands
After running refactor init, these commands are available in Cursor:
/refactor-tool-refactor- Start refactoring analysis (shows capability list)/refactor-tool-refactor <capability-id>- Execute a specific capability directly/refactor-tool-apply- Apply a refactoring proposal/refactor-tool-archive- Archive a completed proposal
Refactoring Capabilities
The tool includes 5 refactor capabilities (each can be executed independently):
- directory-structure - Analyzes directory structure and organization
- component-design - Analyzes component design and architecture
- code-style - Analyzes code style and linting issues
- business-logic - Analyzes business logic and patterns
- styled-jsx-to-css-module - Converts styled-jsx to CSS Module format
Workflow (Default - Independent Mode)
- Run
refactor initto set up the tool - Use
/refactor-tool-refactorto select a capability, or/refactor-tool-refactor <capability-id>to run directly - Review generated OpenSpec proposals
- Apply proposals using
/refactor-tool-applyor manually - Archive completed proposals
- Execute other capabilities as needed (no order required)
Workflow (Optional - Stage Mode)
If you prefer stage-based workflow:
- Use
--stage-modeflag:refactor run <capability> --stage-mode - Execute capabilities in stage order
- Complete all proposals in a stage before moving to next
- Stage gate checks are enforced
Development
# Install dependencies
npm install
# Build
npm run build
# Development mode (watch)
npm run dev
# Run CLI locally
npm run dev:cli
# Test
npm testProject Structure
refactor/
├── AGENTS.md # Instructions for AI assistants
├── project.md # Project context and conventions
├── progress.md # Progress tracking (capability execution history)
├── specs/ # Refactoring specifications
│ ├── directory-structure/
│ ├── component-design/
│ ├── code-style/
│ └── business-logic/
└── changes/ # OpenSpec proposals
├── <change-id>/ # Active proposals
│ ├── proposal.md # Proposal details
│ ├── tasks.md # Implementation tasks
│ ├── design.md # Design decisions (optional)
│ ├── analysis.md # Analysis report (generated by AI)
│ ├── context.md # Skill execution context
│ └── specs/ # Specification deltas
└── archive/ # Archived proposals
└── YYYY-MM-DD-<change-id>/
.cursor/
├── commands/ # Cursor commands
│ ├── refactor-tool-refactor.md
│ ├── refactor-tool-apply.md
│ └── refactor-tool-archive.md
└── skills/ # Refactoring skills
├── directory-structure-refactor/
├── component-design-refactor/
├── code-style-refactor/
└── business-logic-refactor/File Path Conventions
Refactor Tool uses standard file path conventions to ensure AI knows which files to read:
- Analysis Report:
refactor/changes/<change-id>/analysis.md- Generated by AI based on skill capabilities - Proposal Context:
refactor/changes/<change-id>/context.md- Skill execution context (skill name, capability ID, analysis report path, execution params) - Progress Tracking:
refactor/progress.md- Capability execution history and proposal associations
Proposal Completeness:
- Each proposal directory contains all materials for that requirement (proposal.md, tasks.md, design.md, analysis.md, context.md, specs/)
- When archiving, all files in the proposal directory are archived together to
refactor/changes/archive/YYYY-MM-DD-<proposal-id>/ - This ensures no redundant files remain in the project after archiving
Requirements
- Node.js >= 20.19.0
- OpenSpec (installed globally or as dependency)
- Cursor IDE (for full integration)
License
MIT
