Full Auto Code Refactoring
Cross-file dependencies को समझ जाओ, एक instruction से पूरा project को batch refactor करो — variable names change नहीं, real structural refactoring है
Traditional refactoring कितना painful है, तुम बेहतर जानते हो
एक function का नाम बदला, तो 100 files में change करना पड़ता है। बदलने के बाद भी डर रहता है कि कहीं miss हो गया। Tests चलाओ तो 3 जगह crash हो गया। फिर से debug शुरू। Big projects में तो हिलने की हिम्मत भी नहीं रहती, technical debt बढ़ता जाता है। Class को split या modules को extract करना — ये बड़े काम हैं, हाथ से करने में कम से कम एक हफ्ता लग जाता है।
OpenClaw कैसे solve करता है
OpenClaw सिर्फ current file को नहीं देखता — पूरी project directory को read करता है, import chains को analyze करता है, function calls को track करता है, type definitions को समझता है, module dependencies को देखता है, और फिर काम करता है। Change के बाद automatically tests run होती हैं। बस तुम कहो "इस project को class से hooks में convert करो", बाकी सब AI करेगा।
Copy-paste करने लायक Prompts
ये तीन prompts सबसे common refactoring scenarios को cover करते हैं। सीधे copy-paste करो।
Please analyze सभी React Class Component files को current project में.
ये refactoring tasks करो:
1. हर class component को function component + Hooks में convert करो
2. this.state / this.setState → useState
3. componentDidMount / componentWillUnmount → useEffect
4. Reusable logic को custom Hook बना
5. Props interface same रखो, parent components को change न करना पड़े
6. Existing tests run करो, कुछ break न हो
हर file के changes को separately list करो, समझाओ कि क्या changed है और क्यों।
Project की सभी error handling code को analyze करो।
Current status audit:
- सभी try-catch blocks, .catch() calls, error callbacks को find करो
- Inconsistencies को list करो (कहीं error को swallow कर रहे हो, कहीं सिर्फ console.log, कहीं throw)
Unified solution:
1. AppError class बना (code, message, cause के साथ)
2. Global error handling middleware बना
3. सभी business layer में AppError को throw करो, direct Error न फेंको
4. API layer से unified response दो { success: false, error: { code, message } }
5. Modified files की list और diff दे
मुझे यह JavaScript project को TypeScript में migrate करना है।
ये steps follow करो:
1. Project structure analyze करो, tsconfig.json generate करो (strict mode)
2. Entry file से शुरू करके, dependency order में .js → .ts/.tsx करो
3. सभी function parameters और return values में type annotations दो
4. Any usage को minimize करो, specific types use करो
5. Third-party libraries के लिए @types packages install करो
6. types/ directory बना, common type definitions रखो
7. Make sure tsc --noEmit passes, कोई type errors न हों
हर file के changes का summary दे। अगर कहीं any use करना पड़े तो reason दे।
Recommended setup
Refactoring के लिए यह setup suggest करते हैं, AI को ज़्यादा careful और controlled बनाता है।
# .openclaw/skill_config.yaml
refactor:
model: claude-opus-4-6 # Refactoring के लिए Opus best है, cross-file understanding top-notch है
context_depth: full # पूरी project structure read करो
safety:
dry_run: true # पहले preview दिखा, फिर confirm करके write करो
run_tests: true # Change के बाद tests run कर
backup: true # बदलने से पहले backup रख
ignore:
- node_modules/
- dist/
- "*.min.js"
OpenClaw vs Copilot — Refactoring का comparison
- पूरी project की dependency graph को समझता है, एक जगह change करो तो सभी references automatically update हो जाते हैं
- Cross-file bulk rename, common modules extract करो, giant files को split करो
- Change के बाद automatically tests चलाता है, verify करता है कि कुछ break न हो
- Custom refactoring rules और blacklists support करता है
- Mostly current file में completion और suggestions दे सकता है
- Cross-file refactoring के लिए हर file को manually खोलना पड़ता है
- Built-in test validation process नहीं है
- IDE की refactoring features पर depend करता है, capabilities IDE plugin से limited होती हैं
More detailed comparison 👉 OpenClaw vs Copilot · OpenClaw vs Cursor
Real scenario: Large project refactoring
Refactoring के लिए कौन सा model use करें
Refactoring को highest code understanding की ज़रूरत है, इस पर पैसा बचाना मत।
- Claude Opus 4.6 —— Large refactoring के लिए first choice है, cross-file dependency tracking सबसे मज़बूत है
- GPT-4o —— Medium और small refactoring के लिए काफ़ी है, speed ज़्यादा है
- DeepSeek V3.2 —— Budget कम हो तो यह option है, results भी अच्छे आते हैं