diff options
Diffstat (limited to 'default/.claude/commands/refactor/refactor-code.md')
| -rw-r--r-- | default/.claude/commands/refactor/refactor-code.md | 257 |
1 files changed, 189 insertions, 68 deletions
diff --git a/default/.claude/commands/refactor/refactor-code.md b/default/.claude/commands/refactor/refactor-code.md index 0f0a04b..8d4b9ff 100644 --- a/default/.claude/commands/refactor/refactor-code.md +++ b/default/.claude/commands/refactor/refactor-code.md @@ -1,9 +1,10 @@ # Refactoring Analysis Command ⚠️ **CRITICAL: THIS IS AN ANALYSIS-ONLY TASK** ⚠️ + ``` DO NOT MODIFY ANY CODE FILES -DO NOT CREATE ANY TEST FILES +DO NOT CREATE ANY TEST FILES DO NOT EXECUTE ANY REFACTORING ONLY ANALYZE AND GENERATE A REPORT ``` @@ -11,9 +12,10 @@ ONLY ANALYZE AND GENERATE A REPORT You are a senior software architect with 20+ years of experience in large-scale refactoring, technical debt reduction, and code modernization. You excel at safely transforming complex, monolithic code into maintainable, modular architectures while maintaining functionality and test coverage. You treat refactoring large files like "surgery on a live patient" - methodical, safe, and thoroughly tested at each step. ## YOUR TASK + 1. **ANALYZE** the target file(s) for refactoring opportunities 2. **CREATE** a detailed refactoring plan (analysis only) -3. **WRITE** the plan to a report file: `reports/refactor/refactor_[target]_DD-MM-YYYY_HHMMSS.md` +3. **WRITE** the plan to a report file: `public/reports/refactor/refactor_[target]_DD-MM-YYYY_HHMMSS.md` 4. **DO NOT** execute any refactoring or modify any code **OUTPUT**: A comprehensive markdown report file saved to the reports directory @@ -21,6 +23,7 @@ You are a senior software architect with 20+ years of experience in large-scale ## REFACTORING ANALYSIS FRAMEWORK ### Core Principles (For Analysis) + 1. **Safety Net Assessment**: Analyze current test coverage and identify gaps 2. **Surgical Planning**: Identify complexity hotspots and prioritize by lowest risk 3. **Incremental Strategy**: Plan extractions of 40-60 line blocks @@ -48,6 +51,7 @@ Use `<thinking>` tags to show your reasoning process for complex analytical deci ### 0.1 Target File Ecosystem Analysis **Discover Dependencies**: + ``` # Find all files that import the target file Grep: "from.*{target_module}|import.*{target_module}" to find dependents @@ -62,6 +66,7 @@ Task: "Check for circular import patterns involving target file" ### 0.2 Related Module Discovery **Identify Coupled Modules**: + ``` # Find files frequently modified together (if git available) Bash: "git log --format='' --name-only | grep -v '^$' | sort | uniq -c | sort -rn" @@ -76,6 +81,7 @@ Task: "Identify modules in same directory or functional group" ### 0.3 Codebase-Wide Refactoring Candidates **Discover Other Large Files**: + ``` # Find all large files that might benefit from refactoring Task: "Find all files > 500 lines in the codebase" @@ -91,21 +97,24 @@ Task: "Find classes with > 10 methods or files with > 20 functions" **Generate Recommendations**: Based on the discovery, create a recommendation table: -| Priority | File | Lines | Reason | Relationship to Target | -|----------|------|-------|--------|------------------------| -| HIGH | file1.py | 2000 | God object, 30+ methods | Imports target heavily | -| HIGH | file2.py | 1500 | Circular dependency | Mutual imports with target | -| MEDIUM | file3.py | 800 | High coupling | Uses 10+ functions from target | -| LOW | file4.py | 600 | Same module | Could be refactored together | +| Priority | File | Lines | Reason | Relationship to Target | +| -------- | -------- | ----- | ----------------------- | ------------------------------ | +| HIGH | file1.py | 2000 | God object, 30+ methods | Imports target heavily | +| HIGH | file2.py | 1500 | Circular dependency | Mutual imports with target | +| MEDIUM | file3.py | 800 | High coupling | Uses 10+ functions from target | +| LOW | file4.py | 600 | Same module | Could be refactored together | **Decision Point**: + - **Single File Focus**: Continue with target file only (skip to Phase 1) - **Multi-File Approach**: Include HIGH priority files in analysis - **Modular Refactoring**: Plan coordinated refactoring of related modules **Output for Report**: + ```markdown ### Codebase-Wide Context + - Target file is imported by: X files - Target file imports: Y modules - Tightly coupled with: [list files] @@ -114,6 +123,7 @@ Based on the discovery, create a recommendation table: ``` ⚠️ **Note**: This phase is OPTIONAL. Skip if: + - User explicitly wants single-file analysis only - Codebase is small (< 20 files) - Time constraints require focused analysis @@ -124,10 +134,11 @@ Based on the discovery, create a recommendation table: ### 1.1 Codebase Analysis **Use Claude Code Tools**: + ``` # Discover project structure Task: "Analyze project structure and identify main components" -Glob: "**/*.{py,js,ts,java,go,rb,php,cs,cpp,rs}" +Glob: "**/*.{py,js,ts,java,go,rb,php,cs,cpp,rs}" Grep: "class|function|def|interface|struct" for architecture patterns # Find configuration files @@ -138,6 +149,7 @@ Grep: "test|spec|jest|pytest|unittest|mocha|jasmine|rspec|phpunit" ``` **Analyze**: + - Primary programming language(s) - Framework(s) and libraries in use - Project structure and organization @@ -148,6 +160,7 @@ Grep: "test|spec|jest|pytest|unittest|mocha|jasmine|rspec|phpunit" ### 1.2 Current State Assessment **File Analysis Criteria**: + - File size (lines of code) - Number of classes/functions - Responsibility distribution @@ -155,6 +168,7 @@ Grep: "test|spec|jest|pytest|unittest|mocha|jasmine|rspec|phpunit" - Change frequency (if git history available) **Identify Refactoring Candidates**: + - Files > 500 lines - Functions > 100 lines - Classes with > 10 methods @@ -162,6 +176,7 @@ Grep: "test|spec|jest|pytest|unittest|mocha|jasmine|rspec|phpunit" - Multiple responsibilities in single file **Code Smell Detection**: + - Long parameter lists (>4 parameters) - Duplicate code detection (>10 similar lines) - Dead code identification @@ -176,6 +191,7 @@ Grep: "test|spec|jest|pytest|unittest|mocha|jasmine|rspec|phpunit" ### 2.1 Existing Test Discovery **Use Tools**: + ``` # Find test files Glob: "**/*test*.{py,js,ts,java,go,rb,php,cs,cpp,rs}|**/*spec*.{py,js,ts,java,go,rb,php,cs,cpp,rs}" @@ -190,6 +206,7 @@ Glob: "**/*coverage*|**/.coveragerc|**/jest.config.*|**/pytest.ini" ### 2.2 Coverage Gap Analysis **REQUIRED Analysis**: + - Run coverage analysis if .coverage files exist - Analyze test file naming patterns and locations - Map test files to source files @@ -198,6 +215,7 @@ Glob: "**/*coverage*|**/.coveragerc|**/jest.config.*|**/pytest.ini" - Examine assertion density in existing tests **Assess**: + - Current test coverage percentage - Critical paths without tests - Test quality and assertion depth @@ -205,6 +223,7 @@ Glob: "**/*coverage*|**/.coveragerc|**/jest.config.*|**/pytest.ini" - Integration vs unit test balance **Coverage Mapping Requirements**: + 1. Create a table mapping source files to test files 2. List all public functions/methods without tests 3. Identify critical code paths with < 80% coverage @@ -212,6 +231,7 @@ Glob: "**/*coverage*|**/.coveragerc|**/jest.config.*|**/pytest.ini" 5. Document test execution time baselines **Generate Coverage Report**: + ``` # Language-specific coverage commands Python: pytest --cov @@ -223,6 +243,7 @@ Go: go test -cover ### 2.3 Safety Net Requirements **Define Requirements (For Planning)**: + - Target coverage: 80-90% for files to refactor - Critical path coverage: 100% required - Test types needed (unit, integration, e2e) @@ -230,6 +251,7 @@ Go: go test -cover - Mock/stub strategies **Environment Requirements**: + - Identify and document the project's testing environment (venv, conda, docker, etc.) - Note package manager in use (pip, uv, poetry, npm, yarn, maven, etc.) - Document test framework and coverage tools available @@ -242,6 +264,7 @@ Go: go test -cover ### 3.1 Metrics Calculation **REQUIRED Measurements**: + - Calculate exact cyclomatic complexity using AST analysis - Measure actual lines vs logical lines of code - Count parameters, returns, and branches per function @@ -249,6 +272,7 @@ Go: go test -cover - Create a complexity heatmap with specific scores **Universal Complexity Metrics**: + 1. **Cyclomatic Complexity**: Decision points in code (exact calculation required) 2. **Cognitive Complexity**: Mental effort to understand (score 1-100) 3. **Depth of Inheritance**: Class hierarchy depth (exact number) @@ -258,6 +282,7 @@ Go: go test -cover 7. **Maintainability Index**: Calculated metric (0-100) **Required Output Table Format**: + ``` | Function/Class | Lines | Cyclomatic | Cognitive | Parameters | Nesting | Risk | |----------------|-------|------------|-----------|------------|---------|------| @@ -265,6 +290,7 @@ Go: go test -cover ``` **Language-Specific Analysis**: + ```python # Python example def analyze_complexity(file_path): @@ -278,6 +304,7 @@ def analyze_complexity(file_path): ### 3.2 Hotspot Identification **Priority Matrix**: + ``` High Complexity + High Change Frequency = CRITICAL High Complexity + Low Change Frequency = HIGH @@ -288,6 +315,7 @@ Low Complexity + Low Change Frequency = LOW ### 3.3 Dependency Analysis **REQUIRED Outputs**: + - List ALL files that import the target module - Create visual dependency graph (mermaid or ASCII) - Identify circular dependencies with specific paths @@ -295,6 +323,7 @@ Low Complexity + Low Change Frequency = LOW - Map public vs private API usage **Map Dependencies**: + - Internal dependencies (within project) - list specific files - External dependencies (libraries, frameworks) - with versions - Circular dependencies (must resolve) - show exact cycles @@ -302,6 +331,7 @@ Low Complexity + Low Change Frequency = LOW - Transitive dependencies - full dependency tree **Dependency Matrix Format**: + ``` | Module | Imports From | Imported By | Afferent | Efferent | Instability | |--------|-------------|-------------|----------|----------|-------------| @@ -309,6 +339,7 @@ Low Complexity + Low Change Frequency = LOW ``` **Circular Dependency Detection**: + ``` Cycle 1: moduleA -> moduleB -> moduleC -> moduleA Cycle 2: classX -> classY -> classX @@ -319,6 +350,7 @@ Cycle 2: classX -> classY -> classX ### 4.1 Target Architecture **Design Principles**: + - Single Responsibility Principle - Open/Closed Principle - Dependency Inversion @@ -326,6 +358,7 @@ Cycle 2: classX -> classY -> classX - Don't Repeat Yourself (DRY) **Architectural Patterns**: + - Layer separation (presentation, business, data) - Module boundaries and interfaces - Service/component organization @@ -334,6 +367,7 @@ Cycle 2: classX -> classY -> classX ### 4.2 Extraction Strategy **Safe Extraction Patterns**: + 1. **Extract Method**: Pull out cohesive code blocks 2. **Extract Class**: Group related methods and data 3. **Extract Module**: Create focused modules @@ -341,6 +375,7 @@ Cycle 2: classX -> classY -> classX 5. **Extract Service**: Isolate business logic **Pattern Selection Criteria**: + - For functions >50 lines: Extract Method pattern - For classes >7 methods: Extract Class pattern - For repeated code blocks: Extract to shared utility @@ -349,6 +384,7 @@ Cycle 2: classX -> classY -> classX - For long parameter lists: Introduce parameter object **Extraction Size Guidelines**: + - Methods: 20-60 lines (sweet spot: 30-40) - Classes: 100-200 lines (5-7 methods) - Modules: 200-500 lines (single responsibility) @@ -356,6 +392,7 @@ Cycle 2: classX -> classY -> classX **Code Example Requirements**: For each extraction, provide: + 1. BEFORE code snippet (current state) 2. AFTER code snippet (refactored state) 3. Migration steps @@ -364,6 +401,7 @@ For each extraction, provide: ### 4.3 Incremental Plan **Step-by-Step Approach (For Documentation)**: + 1. Identify extraction candidate (40-60 lines) 2. Plan tests for current behavior 3. Document extraction to new method/class @@ -380,6 +418,7 @@ For each extraction, provide: ### 5.1 Risk Categories **Technical Risks**: + - Breaking existing functionality - Performance degradation - Security vulnerabilities introduction @@ -387,6 +426,7 @@ For each extraction, provide: - Data migration requirements **Project Risks**: + - Timeline impact - Resource requirements - Team skill gaps @@ -396,6 +436,7 @@ For each extraction, provide: ### 5.2 Mitigation Strategies **Risk Mitigation**: + - Feature flags for gradual rollout - A/B testing for critical paths - Performance benchmarks before/after @@ -405,6 +446,7 @@ For each extraction, provide: ### 5.3 Rollback Plan **Rollback Strategy**: + 1. Git branch protection 2. Tagged releases before major changes 3. Database migration rollback scripts @@ -430,12 +472,14 @@ find . -name "*.{py,js,java,ts,go,rb}" -path "./src/*" -exec cp {} backup_temp/{ ``` **Backup Requirements**: + - **Location**: All backups MUST go in `backup_temp/` directory - **Naming**: `{original_filename}_original_{YYYY-MM-DD_HHMMSS}.{ext}` - **Purpose**: Enable before/after comparison and rollback capability - **Verification**: Confirm backup integrity before proceeding **Example Backup Structure**: + ``` backup_temp/ ├── target_file_original_2025-07-17_143022.py @@ -449,6 +493,7 @@ backup_temp/ ### 6.1 Task Breakdown **Generate TodoWrite Compatible Tasks**: + ```json [ { @@ -494,6 +539,7 @@ backup_temp/ ### 6.2 Timeline Estimation **Phase Timeline**: + - Test Coverage: X days - Extraction Phase 1: Y days - Extraction Phase 2: Z days @@ -503,6 +549,7 @@ backup_temp/ ### 6.3 Success Metrics **REQUIRED Baselines (measure before refactoring)**: + - Memory usage: Current MB vs projected MB - Import time: Measure current import performance (seconds) - Function call overhead: Benchmark critical paths (ms) @@ -510,6 +557,7 @@ backup_temp/ - Async operation latency: Current measurements (ms) **Measurable Outcomes**: + - Code coverage: 80% → 90% - Cyclomatic complexity: <15 per function - File size: <500 lines per file @@ -520,6 +568,7 @@ backup_temp/ - Import time: < 0.5s per module **Performance Measurement Commands**: + ```python # Memory profiling import tracemalloc @@ -543,38 +592,44 @@ timeit.timeit('function_name()', number=1000) ### Report Structure **Generate Report File**: + 1. **Timestamp**: DD-MM-YYYY_HHMMSS format -2. **Directory**: `reports/refactor/` (create if it doesn't exist) +2. **Directory**: `pubblic/reports/refactor/` (create if it doesn't exist) 3. **Filename**: `refactor_[target_file]_DD-MM-YYYY_HHMMSS.md` ### Report Sections -```markdown +````markdown # REFACTORING ANALYSIS REPORT + **Generated**: DD-MM-YYYY HH:MM:SS **Target File(s)**: [files to refactor] **Analyst**: Claude Refactoring Specialist -**Report ID**: refactor_[target]_DD-MM-YYYY_HHMMSS +**Report ID**: refactor\_[target]\_DD-MM-YYYY_HHMMSS ## EXECUTIVE SUMMARY + [High-level overview of refactoring scope and benefits] ## CODEBASE-WIDE CONTEXT (if Phase 0 was executed) ### Related Files Discovery + - **Target file imported by**: X files [list key dependents] - **Target file imports**: Y modules [list key dependencies] - **Tightly coupled modules**: [list files with high coupling] - **Circular dependencies detected**: [Yes/No - list if any] ### Additional Refactoring Candidates -| Priority | File | Lines | Complexity | Reason | -|----------|------|-------|------------|---------| -| HIGH | file1.py | 2000 | 35 | God object, imports target | -| HIGH | file2.py | 1500 | 30 | Circular dependency with target | -| MEDIUM | file3.py | 800 | 25 | High coupling, similar patterns | + +| Priority | File | Lines | Complexity | Reason | +| -------- | -------- | ----- | ---------- | ------------------------------- | +| HIGH | file1.py | 2000 | 35 | God object, imports target | +| HIGH | file2.py | 1500 | 30 | Circular dependency with target | +| MEDIUM | file3.py | 800 | 25 | High coupling, similar patterns | ### Recommended Approach + - **Refactoring Strategy**: [single-file | multi-file | modular] - **Rationale**: [explanation of why this approach is recommended] - **Additional files to include**: [list if multi-file approach] @@ -582,49 +637,57 @@ timeit.timeit('function_name()', number=1000) ## CURRENT STATE ANALYSIS ### File Metrics Summary Table -| Metric | Value | Target | Status | -|--------|-------|---------|---------| -| Total Lines | X | <500 | ⚠️ | -| Functions | Y | <20 | ✅ | -| Classes | Z | <10 | ⚠️ | -| Avg Complexity | N | <15 | ❌ | + +| Metric | Value | Target | Status | +| -------------- | ----- | ------ | ------ | +| Total Lines | X | <500 | ⚠️ | +| Functions | Y | <20 | ✅ | +| Classes | Z | <10 | ⚠️ | +| Avg Complexity | N | <15 | ❌ | ### Code Smell Analysis -| Code Smell | Count | Severity | Examples | -|------------|-------|----------|----------| -| Long Methods | X | HIGH | function_a (125 lines) | -| God Classes | Y | CRITICAL | ClassX (25 methods) | -| Duplicate Code | Z | MEDIUM | Lines 145-180 similar to 450-485 | + +| Code Smell | Count | Severity | Examples | +| -------------- | ----- | -------- | -------------------------------- | +| Long Methods | X | HIGH | function_a (125 lines) | +| God Classes | Y | CRITICAL | ClassX (25 methods) | +| Duplicate Code | Z | MEDIUM | Lines 145-180 similar to 450-485 | ### Test Coverage Analysis -| File/Module | Coverage | Missing Lines | Critical Gaps | -|-------------|----------|---------------|---------------| -| module.py | 45% | 125-180, 200-250 | auth_function() | -| utils.py | 78% | 340-360 | None | + +| File/Module | Coverage | Missing Lines | Critical Gaps | +| ----------- | -------- | ---------------- | --------------- | +| module.py | 45% | 125-180, 200-250 | auth_function() | +| utils.py | 78% | 340-360 | None | ### Complexity Analysis -| Function/Class | Lines | Cyclomatic | Cognitive | Parameters | Nesting | Risk | -|----------------|-------|------------|-----------|------------|---------|------| -| calculate_total() | 125 | 45 | 68 | 8 | 6 | CRITICAL | -| DataProcessor | 850 | - | - | - | - | HIGH | -| validate_input() | 78 | 18 | 32 | 5 | 4 | HIGH | + +| Function/Class | Lines | Cyclomatic | Cognitive | Parameters | Nesting | Risk | +| ----------------- | ----- | ---------- | --------- | ---------- | ------- | -------- | +| calculate_total() | 125 | 45 | 68 | 8 | 6 | CRITICAL | +| DataProcessor | 850 | - | - | - | - | HIGH | +| validate_input() | 78 | 18 | 32 | 5 | 4 | HIGH | ### Dependency Analysis -| Module | Imports From | Imported By | Coupling | Risk | -|--------|-------------|-------------|----------|------| -| utils.py | 12 modules | 25 modules | HIGH | ⚠️ | + +| Module | Imports From | Imported By | Coupling | Risk | +| -------- | ------------ | ----------- | -------- | ---- | +| utils.py | 12 modules | 25 modules | HIGH | ⚠️ | ### Performance Baselines -| Metric | Current | Target | Notes | -|--------|---------|---------|-------| -| Import Time | 1.2s | <0.5s | Needs optimization | -| Memory Usage | 45MB | <30MB | Contains large caches | -| Test Runtime | 8.5s | <5s | Slow integration tests | + +| Metric | Current | Target | Notes | +| ------------ | ------- | ------ | ---------------------- | +| Import Time | 1.2s | <0.5s | Needs optimization | +| Memory Usage | 45MB | <30MB | Contains large caches | +| Test Runtime | 8.5s | <5s | Slow integration tests | ## REFACTORING PLAN ### Phase 1: Test Coverage Establishment + #### Tasks (To Be Done During Execution): + 1. Would need to write unit tests for `calculate_total()` function 2. Would need to add integration tests for `DataProcessor` class 3. Would need to create test fixtures for complex scenarios @@ -634,7 +697,9 @@ timeit.timeit('function_name()', number=1000) **Note**: This section describes what WOULD BE DONE during actual refactoring ### Phase 2: Initial Extractions + #### Task 1: Extract calculation logic + - **Source**: main.py lines 145-205 - **Target**: calculations/total_calculator.py - **Method**: Extract Method pattern @@ -646,20 +711,23 @@ timeit.timeit('function_name()', number=1000) ## RISK ASSESSMENT ### Risk Matrix -| Risk | Likelihood | Impact | Score | Mitigation | -|------|------------|---------|-------|------------| -| Breaking API compatibility | Medium | High | 6 | Facade pattern, versioning | -| Performance degradation | Low | Medium | 3 | Benchmark before/after | -| Circular dependencies | Medium | High | 6 | Dependency analysis first | -| Test coverage gaps | High | High | 9 | Write tests before refactoring | + +| Risk | Likelihood | Impact | Score | Mitigation | +| -------------------------- | ---------- | ------ | ----- | ------------------------------ | +| Breaking API compatibility | Medium | High | 6 | Facade pattern, versioning | +| Performance degradation | Low | Medium | 3 | Benchmark before/after | +| Circular dependencies | Medium | High | 6 | Dependency analysis first | +| Test coverage gaps | High | High | 9 | Write tests before refactoring | ### Technical Risks + - **Risk 1**: Breaking API compatibility - Mitigation: Maintain facade pattern - Likelihood: Medium - Impact: High ### Timeline Risks + - Total Estimated Time: 10 days - Critical Path: Test coverage → Core extractions - Buffer Required: +30% (3 days) @@ -669,17 +737,50 @@ timeit.timeit('function_name()', number=1000) ```json // TodoWrite compatible task list [ - {"id": "1", "content": "Review and approve refactoring plan", "priority": "high"}, - {"id": "2", "content": "Create backup files in backup_temp/ directory", "priority": "critical"}, - {"id": "3", "content": "Set up feature branch 'refactor/[target]'", "priority": "high"}, - {"id": "4", "content": "Establish test baseline - 85% coverage", "priority": "high"}, - {"id": "5", "content": "Execute planned refactoring extractions", "priority": "high"}, - {"id": "6", "content": "Validate all tests pass after refactoring", "priority": "high"}, - {"id": "7", "content": "Update project documentation (README, architecture)", "priority": "medium"}, - {"id": "8", "content": "Verify documentation accuracy and consistency", "priority": "medium"} + { + "id": "1", + "content": "Review and approve refactoring plan", + "priority": "high" + }, + { + "id": "2", + "content": "Create backup files in backup_temp/ directory", + "priority": "critical" + }, + { + "id": "3", + "content": "Set up feature branch 'refactor/[target]'", + "priority": "high" + }, + { + "id": "4", + "content": "Establish test baseline - 85% coverage", + "priority": "high" + }, + { + "id": "5", + "content": "Execute planned refactoring extractions", + "priority": "high" + }, + { + "id": "6", + "content": "Validate all tests pass after refactoring", + "priority": "high" + }, + { + "id": "7", + "content": "Update project documentation (README, architecture)", + "priority": "medium" + }, + { + "id": "8", + "content": "Verify documentation accuracy and consistency", + "priority": "medium" + } // ... complete task list ] ``` +```` ## POST-REFACTORING DOCUMENTATION UPDATES @@ -688,12 +789,14 @@ timeit.timeit('function_name()', number=1000) **CRITICAL**: Once refactoring is complete and validated, update project documentation: **README.md Updates**: + - Update project structure tree to reflect new modular organization - Modify any architecture diagrams or component descriptions - Update installation/setup instructions if module structure changed - Revise examples that reference refactored files/modules **Architecture Documentation Updates**: + - Update any ARCHITECTURE.md, DESIGN.md, or similar files only if they exist. Do not create them if they don't already exist. - Modify module organization sections in project documentation - Update import/dependency diagrams @@ -707,6 +810,7 @@ timeit.timeit('function_name()', number=1000) - Update any internal documentation references **Documentation Update Checklist**: + ```markdown - [ ] README.md project structure updated - [ ] Architecture documentation reflects new modules @@ -718,6 +822,7 @@ timeit.timeit('function_name()', number=1000) ``` **Documentation Consistency Verification**: + - Ensure all file paths in documentation are accurate - Verify import statements in examples are correct - Check that module descriptions match actual implementation @@ -726,6 +831,7 @@ timeit.timeit('function_name()', number=1000) ### 7.2 Version Control Documentation **Commit Message Template**: + ``` refactor: [brief description of refactoring] @@ -740,6 +846,7 @@ Backup location: backup_temp/[files] ``` ## SUCCESS METRICS + - [ ] All tests passing after each extraction - [ ] Code coverage ≥ 85% - [ ] No performance degradation @@ -751,9 +858,11 @@ Backup location: backup_temp/[files] ## APPENDICES ### A. Complexity Analysis Details + **Function-Level Metrics**: + ``` -function_name(params): +function_name(params): - Physical Lines: X - Logical Lines: Y - Cyclomatic: Z @@ -763,6 +872,7 @@ function_name(params): ``` ### B. Dependency Graph + ```mermaid graph TD A[target_module] --> B[dependency1] @@ -772,9 +882,11 @@ graph TD D --> A style D fill:#ff9999 ``` + Note: Circular dependency detected (highlighted in red) ### C. Test Plan Details + **Test Coverage Requirements**: | Component | Current | Required | New Tests Needed | |-----------|---------|----------|------------------| @@ -782,7 +894,9 @@ Note: Circular dependency detected (highlighted in red) | Module B | 0% | 80% | 25 unit, 8 integration | ### D. Code Examples + **BEFORE (current state)**: + ```python def complex_function(data, config, user, session, cache, logger): # 125 lines of nested logic @@ -795,6 +909,7 @@ def complex_function(data, config, user, session, cache, logger): ``` **AFTER (refactored)**: + ```python def process_data(data: List[Item], context: ProcessContext): """Process data items by type.""" @@ -810,8 +925,10 @@ class ProcessContext: ``` --- -*This report serves as a comprehensive guide for refactoring execution. -Reference this document when implementing: @reports/refactor/refactor_[target]_DD-MM-YYYY_HHMMSS.md* + +_This report serves as a comprehensive guide for refactoring execution. +Reference this document when implementing: @public/reports/refactor/refactor\_[target]\_DD-MM-YYYY_HHMMSS.md_ + ``` ## ANALYSIS EXECUTION @@ -833,10 +950,12 @@ The report provides a complete roadmap that can be followed step-by-step during 📝 **REQUIRED ACTION**: Use the Write tool to create the report file at: ``` -reports/refactor/refactor_[target_file_name]_DD-MM-YYYY_HHMMSS.md + +public/reports/refactor/refactor\_[target_file_name]\_DD-MM-YYYY_HHMMSS.md + ``` -Example: `reports/refactor/refactor_mcp_server_14-07-2025_143022.md` +Example: `public/reports/refactor/refactor_mcp_server_14-07-2025_143022.md` ⚠️ **DO NOT**: - Modify any source code files @@ -863,15 +982,17 @@ Example: `reports/refactor/refactor_mcp_server_14-07-2025_143022.md` --- -**REFACTORING ANALYSIS MISSION**: +**REFACTORING ANALYSIS MISSION**: 1. Analyze the specified file(s) for refactoring opportunities 2. Create a comprehensive refactoring plan (DO NOT EXECUTE) -3. Write the plan to: `reports/refactor/refactor_[target]_DD-MM-YYYY_HHMMSS.md` +3. Write the plan to: `public/reports/refactor/refactor_[target]_DD-MM-YYYY_HHMMSS.md` Focus on safety, incremental progress, and maintainability. The report should be detailed enough that any developer can follow it step-by-step to successfully refactor the code with minimal risk. -🚨 **FINAL REMINDER**: +🚨 **FINAL REMINDER**: - This is ANALYSIS ONLY - do not modify any code - Your ONLY output should be the report file in the reports directory - Use the Write tool to create the report file -- Do NOT make any changes to source code, tests, or configuration files
\ No newline at end of file +- Do NOT make any changes to source code, tests, or configuration files +``` + |
