Complete refactoring workflow with tracking, validation, and cross-layer impact checklists. Integrates with beads for progress tracking and ensures no references to old names remain after refactoring.
Systematic refactoring with tracking, validation, and completeness verification. Automatically logs changes to beads and validates no old references remain before marking tasks complete.
/plugin marketplace add Kaakati/rails-enterprise-dev/plugin install reactree-rails-dev@manifest-marketplaceThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Systematic refactoring with tracking, validation, and completeness verification.
# 1. Record what you're refactoring
record_refactoring "Payment" "Transaction" "class_rename"
# 2. Update files, track progress
update_refactoring_progress "Payment" "app/models/transaction.rb"
# 3. Validate no old references remain
validate_refactoring "Payment" "Transaction"
Start refactoring by recording what's being changed:
record_refactoring() {
local old_name=$1
local new_name=$2
local refactor_type=$3 # class_rename, attribute_rename, method_rename, table_rename
if [ -n "$TASK_ID" ] && command -v bd &> /dev/null; then
bd comment $TASK_ID "🔄 Refactoring Log: $old_name → $new_name
**Type**: $refactor_type
**Started**: $(date -u +"%Y-%m-%d %H:%M:%S UTC")
**Status**: ⏳ In Progress
### Changes Planned
1. **$(echo $refactor_type | sed 's/_/ /g')**: \`$old_name\` → \`$new_name\`
### Affected Files (Auto-detected)
\`\`\`bash
# Ruby files referencing old name
$(rg --files-with-matches \"\\b$old_name\\b\" --type ruby 2>/dev/null | head -20 || echo "None detected")
\`\`\`
### Validation Checklist
- [ ] No references to \`$old_name\` in Ruby files
- [ ] No references in view templates
- [ ] No references in routes
- [ ] No references in specs
- [ ] No references in factories
- [ ] Migration files checked (if applicable)"
fi
}
# Examples:
# record_refactoring "Payment" "Transaction" "class_rename"
# record_refactoring "user_id" "account_id" "attribute_rename"
# record_refactoring "payments" "transactions" "table_rename"
Track progress as files are updated:
update_refactoring_progress() {
local old_name=$1
local file_updated=$2
if [ -n "$TASK_ID" ] && command -v bd &> /dev/null; then
bd comment $TASK_ID "✅ Refactoring Progress: Updated \`$file_updated\`
Old references to \`$old_name\` in this file have been updated.
Remaining files: $(rg --files-with-matches \"\\b$old_name\\b\" --type ruby 2>/dev/null | wc -l || echo "?")"
fi
}
Validate all references have been updated:
validate_refactoring() {
local old_name=$1
local new_name=$2
echo "🔍 Validating refactoring: $old_name → $new_name"
# Check for remaining references
local remaining=$(rg --count "\\b$old_name\\b" --type ruby --type erb 2>/dev/null | wc -l)
if [ "$remaining" -gt 0 ]; then
echo "❌ Refactoring validation failed"
echo "Found $remaining files still referencing '$old_name':"
rg --files-with-matches "\\b$old_name\\b" --type ruby --type erb 2>/dev/null
if [ -n "$TASK_ID" ] && command -v bd &> /dev/null; then
bd update $TASK_ID --status blocked
fi
return 1
else
echo "✅ Refactoring validation passed"
echo "All references to '$old_name' successfully updated."
return 0
fi
}
record_refactoring()update_refactoring_progress()validate_refactoring()# Phase starts: Renaming Payment to Transaction
# Step 1: Record refactoring
record_refactoring "Payment" "Transaction" "class_rename"
# Step 2: Update model file
mv app/models/payment.rb app/models/transaction.rb
# Update class name in file
sed -i 's/class Payment/class Transaction/g' app/models/transaction.rb
update_refactoring_progress "Payment" "app/models/transaction.rb"
# Step 3: Update associations in other models
# ... update files ...
update_refactoring_progress "Payment" "app/models/account.rb"
# Step 4: Update controller
mv app/controllers/payments_controller.rb app/controllers/transactions_controller.rb
# ... update class name and references ...
update_refactoring_progress "Payment" "app/controllers/transactions_controller.rb"
# Step 5: Update views, specs, factories, routes
# ... update all remaining files ...
# Step 6: Validate completeness
validate_refactoring "Payment" "Transaction"
if [ $? -eq 0 ]; then
echo "✅ Refactoring complete"
else
echo "❌ Refactoring incomplete, fix remaining references"
fi
When renaming Payment → Transaction:
Ruby Layer:
has_many :payments)@payment)"Payment")View Layer:
app/views/payments/)Routes:
resources :payments)Tests:
:payment, :payments)JavaScript/Frontend:
payment_controller.js)PaymentController)data-controller="payment")data-action="payment#submit")payment:updated)#payment-form)I18n:
activerecord.models.payment)Configuration:
When renaming user_id → account_id:
Database:
rails db:migrateModel:
:foreign_key option)Controller:
Views:
Tests:
API:
JavaScript:
I18n:
activerecord.attributes.model.user_id)When renaming payments → transactions:
rails db:migratetable_name declaration (if explicit)When renaming payment → transaction in frontend:
payment_controller.js → transaction_controller.js)PaymentController → TransactionController)When moving Services::Payment → Billing::Transaction:
app/services/payment.rb → app/billing/transaction.rb)Create .refactorignore to exclude files from validation:
# .refactorignore - Files to exclude from refactoring validation
# Legacy compatibility layer
lib/legacy_api_adapter.rb
# Historical documentation
CHANGELOG.md
docs/migration_guide.md
# Rename migrations (reference old names by design)
db/migrate/*_rename_*.rb
# External API contracts (can't change)
app/serializers/api/v1/*_serializer.rb
Refactoring workflow integrates with beads for:
blocked if validation fails# Set TASK_ID before starting refactoring
export TASK_ID="PROJ-123"
# All functions will automatically log to beads
record_refactoring "Payment" "Transaction" "class_rename"
update_refactoring_progress "Payment" "app/models/transaction.rb"
validate_refactoring "Payment" "Transaction"
| Function | Purpose | Example |
|---|---|---|
record_refactoring | Start tracking | record_refactoring "Old" "New" "class_rename" |
update_refactoring_progress | Track file update | update_refactoring_progress "Old" "path/file.rb" |
validate_refactoring | Check completeness | validate_refactoring "Old" "New" |
| Refactor Type | Key Layers to Check |
|---|---|
class_rename | Model, Controller, Views, Routes, Specs, JS |
attribute_rename | Model, Controller params, Views, Specs, JS values |
table_rename | Migration, Schema, Raw SQL |
method_rename | All call sites, Specs |
namespace_move | File paths, Autoloading, All references |
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.