# Tiered Remediation System Intelligent remediation that provides lightweight quick fixes for simple issues and comprehensive remediation stories for complex problems. [[LLM: This tiered system uses 300-800 tokens for simple fixes vs 1500-2000+ tokens for full remediation stories]] ## Remediation Tiers ### **Tier 1: Environment-Adaptive Quick Fixes** (300-500 tokens) ```bash # Auto-initialize environment detection if needed if [ -z "$BMAD_PRIMARY_LANGUAGE" ]; then Read tool: bmad-core/tasks/auto-language-init.md fi if [ -z "$USE_IDE_TOOLS" ]; then Read tool: bmad-core/tasks/lightweight-ide-detection.md fi # Immediate fixes for common, simple issues using environment-appropriate tools provide_quick_fixes() { local ISSUE_TYPE="$1" local ISSUE_DESCRIPTION="$2" echo "๐Ÿš€ Tier 1: Quick Fix Available ($DETECTED_IDE environment)" echo "Language: $BMAD_PRIMARY_LANGUAGE | Tools: $([ "$USE_IDE_TOOLS" = "true" ] && echo "Native" || echo "CLI Batched")" case "$ISSUE_TYPE" in "simulation_patterns") echo "๐ŸŽฏ Simulation Pattern Quick Fixes:" echo "โ€ข Replace Random.NextDouble() with actual business calculation" echo "โ€ข Change Task.FromResult() to real async operation" echo "โ€ข Remove TODO/HACK comments and implement logic" echo "โ€ข Replace hardcoded values with configuration" echo "" echo "โฑ๏ธ Estimated time: 5-15 minutes" echo "๐Ÿ“‹ Action: Direct implementation - no story needed" ;; "missing_tests") echo "๐Ÿงช Missing Test Quick Fixes:" echo "โ€ข Add basic unit tests for new methods" echo "โ€ข Copy/adapt existing similar test patterns" echo "โ€ข Use test templates for standard CRUD operations" echo "โ€ข Focus on happy path scenarios first" echo "" echo "โฑ๏ธ Estimated time: 10-20 minutes" echo "๐Ÿ“‹ Action: Add tests directly to current story" ;; "minor_violations") echo "๐Ÿ“ Code Standard Quick Fixes:" echo "โ€ข Fix naming convention violations" echo "โ€ข Add missing XML documentation" echo "โ€ข Remove unused using statements" echo "โ€ข Apply consistent formatting" echo "" echo "โฑ๏ธ Estimated time: 5-10 minutes" echo "๐Ÿ“‹ Action: Apply fixes immediately" ;; esac } ``` ### **Tier 2: Environment-Adaptive Guided Fixes** (500-800 tokens) ```bash # Auto-initialize environment detection if needed if [ -z "$BMAD_PRIMARY_LANGUAGE" ]; then Read tool: bmad-core/tasks/auto-language-init.md fi if [ -z "$USE_IDE_TOOLS" ]; then Read tool: bmad-core/tasks/lightweight-ide-detection.md fi # Structured guidance for moderate complexity issues using environment-appropriate methods provide_guided_fixes() { local ISSUE_TYPE="$1" local COMPLEXITY_SCORE="$2" echo "โš–๏ธ Tier 2: Guided Fix Approach ($DETECTED_IDE environment)" echo "Language: $BMAD_PRIMARY_LANGUAGE | Complexity: $COMPLEXITY_SCORE" case "$ISSUE_TYPE" in "interface_mismatches") echo "๐Ÿ”Œ Interface Implementation Guidance:" echo "" echo "๐Ÿ” Step 1: Analyze Interface Contract" echo "โ€ข Review interface definition and expected signatures" echo "โ€ข Check async/sync patterns required" echo "โ€ข Identify missing or incorrect method implementations" echo "" echo "๐Ÿ”ง Step 2: Update Implementation" echo "โ€ข Implement missing interface members" echo "โ€ข Fix method signature mismatches" echo "โ€ข Ensure return types match interface" echo "" echo "โœ… Step 3: Validate Integration" echo "โ€ข Run tests to verify interface compliance" echo "โ€ข Check calling code still works correctly" echo "โ€ข Validate dependency injection still functions" echo "" echo "โฑ๏ธ Estimated time: 20-40 minutes" echo "๐Ÿ“‹ Action: Follow guided steps within current story" ;; "architectural_violations") echo "๐Ÿ—๏ธ Architecture Compliance Guidance:" echo "" echo "๐Ÿ“ Step 1: Identify Violation Pattern" echo "โ€ข Check against established architectural patterns" echo "โ€ข Review similar implementations for consistency" echo "โ€ข Understand intended separation of concerns" echo "" echo "๐Ÿ”„ Step 2: Refactor to Compliance" echo "โ€ข Move business logic to appropriate layer" echo "โ€ข Extract services or repositories as needed" echo "โ€ข Apply dependency injection patterns" echo "" echo "๐Ÿงช Step 3: Test Architectural Changes" echo "โ€ข Verify all tests still pass" echo "โ€ข Check integration points work correctly" echo "โ€ข Validate performance hasn't degraded" echo "" echo "โฑ๏ธ Estimated time: 30-60 minutes" echo "๐Ÿ“‹ Action: Refactor within current story scope" ;; esac } ``` ### **Tier 3: Environment-Adaptive Full Remediation Stories** (1500-2000+ tokens) ```bash # Auto-initialize environment detection if needed if [ -z "$BMAD_PRIMARY_LANGUAGE" ]; then Read tool: bmad-core/tasks/auto-language-init.md fi if [ -z "$USE_IDE_TOOLS" ]; then Read tool: bmad-core/tasks/lightweight-ide-detection.md fi # Complex issues requiring dedicated remediation stories with environment context create_remediation_story() { local ISSUE_TYPE="$1" local ORIGINAL_STORY="$2" local COMPLEXITY_SCORE="$3" echo "๐Ÿšจ Tier 3: Full Remediation Story Required ($DETECTED_IDE environment)" echo "Language: $BMAD_PRIMARY_LANGUAGE | Complexity Score: $COMPLEXITY_SCORE (>70 threshold met)" echo "Environment Tools: $([ "$USE_IDE_TOOLS" = "true" ] && echo "Native IDE integration" || echo "CLI batch mode")" echo "" # Execute comprehensive remediation story creation echo "๐Ÿ”„ Creating dedicated remediation story..." Read tool: bmad-core/tasks/create-remediation-story.md echo "๐Ÿ“‹ Remediation story generated with:" echo "โ€ข Root cause analysis" echo "โ€ข Regression prevention measures" echo "โ€ข Step-by-step implementation plan" echo "โ€ข Comprehensive testing strategy" echo "โ€ข Integration validation checklist" } ``` ## Smart Triage Logic ### **Environment-Adaptive Issue Classification** (100-200 tokens) ```bash # Auto-initialize environment detection if needed if [ -z "$BMAD_PRIMARY_LANGUAGE" ]; then Read tool: bmad-core/tasks/auto-language-init.md fi if [ -z "$USE_IDE_TOOLS" ]; then Read tool: bmad-core/tasks/lightweight-ide-detection.md fi # Intelligent issue assessment and tier assignment using environment-appropriate analysis classify_remediation_need() { local AUDIT_RESULTS="$1" echo "๐Ÿ“Š Environment-Adaptive Issue Classification:" echo "Analysis Environment: $DETECTED_IDE | Language: $BMAD_PRIMARY_LANGUAGE" # Extract key metrics using environment-appropriate methods if [ "$USE_IDE_TOOLS" = "true" ]; then # Use native IDE tools for pattern analysis echo "Using native IDE tools for issue pattern detection" # Would use Grep tool with appropriate patterns for simulation detection # Would use Read tool for audit results analysis fi # Universal metric extraction (works in all environments) SIMULATION_COUNT=$(echo "$AUDIT_RESULTS" | grep -c "simulation pattern" || echo 0) MISSING_TESTS=$(echo "$AUDIT_RESULTS" | grep -c "missing test" || echo 0) INTERFACE_ERRORS=$(echo "$AUDIT_RESULTS" | grep -c "interface mismatch" || echo 0) ARCHITECTURE_VIOLATIONS=$(echo "$AUDIT_RESULTS" | grep -c "architectural violation" || echo 0) BUILD_ERRORS=$(echo "$AUDIT_RESULTS" | grep -c "build error" || echo 0) # Calculate complexity score COMPLEXITY_SCORE=0 COMPLEXITY_SCORE=$((COMPLEXITY_SCORE + SIMULATION_COUNT * 5)) COMPLEXITY_SCORE=$((COMPLEXITY_SCORE + MISSING_TESTS * 3)) COMPLEXITY_SCORE=$((COMPLEXITY_SCORE + INTERFACE_ERRORS * 10)) COMPLEXITY_SCORE=$((COMPLEXITY_SCORE + ARCHITECTURE_VIOLATIONS * 15)) COMPLEXITY_SCORE=$((COMPLEXITY_SCORE + BUILD_ERRORS * 8)) echo "๐Ÿ“Š Remediation Complexity Assessment:" echo "Simulation Patterns: $SIMULATION_COUNT" echo "Missing Tests: $MISSING_TESTS" echo "Interface Errors: $INTERFACE_ERRORS" echo "Architecture Violations: $ARCHITECTURE_VIOLATIONS" echo "Build Errors: $BUILD_ERRORS" echo "Complexity Score: $COMPLEXITY_SCORE" # Tier assignment logic if [ $COMPLEXITY_SCORE -le 20 ]; then echo "๐Ÿš€ TIER 1 - Quick fixes sufficient" return 1 elif [ $COMPLEXITY_SCORE -le 50 ]; then echo "โš–๏ธ TIER 2 - Guided fixes recommended" return 2 else echo "๐Ÿšจ TIER 3 - Full remediation story required" return 3 fi } ``` ## Integration with Quality Framework ### **Environment-Adaptive Auto-Triage After Reality Audit** ```bash # Auto-initialize environment detection if needed if [ -z "$BMAD_PRIMARY_LANGUAGE" ]; then Read tool: bmad-core/tasks/auto-language-init.md fi if [ -z "$USE_IDE_TOOLS" ]; then Read tool: bmad-core/tasks/lightweight-ide-detection.md fi # Automatic remediation routing based on audit results with environment optimization auto_remediation_triage() { local STORY_FILE="$1" local AUDIT_RESULTS="$2" echo "๐Ÿ”„ Environment-Adaptive Auto-Triage:" echo "Environment: $DETECTED_IDE | Language: $BMAD_PRIMARY_LANGUAGE" # Classify remediation needs using environment-aware analysis classify_remediation_need "$AUDIT_RESULTS" TIER_LEVEL=$? case $TIER_LEVEL in 1) echo "๐Ÿš€ Applying Tier 1 quick fixes..." provide_quick_fixes "simulation_patterns" "$AUDIT_RESULTS" echo "๐Ÿ’ก Tokens used: ~400 (quick fixes provided)" ;; 2) echo "โš–๏ธ Providing Tier 2 guided fixes..." provide_guided_fixes "interface_mismatches" "$COMPLEXITY_SCORE" echo "๐Ÿ’ก Tokens used: ~700 (guided approach provided)" ;; 3) echo "๐Ÿšจ Creating Tier 3 remediation story..." create_remediation_story "complex_issues" "$STORY_FILE" "$COMPLEXITY_SCORE" echo "๐Ÿ’ก Tokens used: ~1800 (full remediation story created)" ;; esac } ``` ### **Environment-Adaptive QA Agent Commands** ```bash *quick-fix # Tier 1 - immediate fixes (300-500 tokens) - Auto-adapts to current IDE *guided-fix # Tier 2 - guided approach (500-800 tokens) - Uses environment-appropriate tools *create-remediation # Tier 3 - full story (1500-2000+ tokens) - Environment context included *auto-triage # Smart triage based on complexity (100-2000 tokens) - Universal IDE compatibility # Environment context automatically included in all commands: # - Uses Grep/Read/Glob tools in Claude Code CLI for pattern detection # - Falls back to batched commands in traditional CLI environments # - Preserves language-specific remediation patterns from auto-detection # - Optimizes token usage based on IDE capabilities ``` ## Token Usage Optimization ### **Tier Distribution Analysis** Based on typical quality audit results: | Tier | Percentage | Token Cost | Use Case | |------|------------|------------|----------| | **Tier 1** | 60% | 300-500 | Simple simulation patterns, minor violations | | **Tier 2** | 25% | 500-800 | Interface mismatches, moderate architecture issues | | **Tier 3** | 15% | 1,500-2,000 | Complex architectural problems, major refactoring | ### **Expected Token Savings** **Previous Approach (Always Full Remediation):** - 10 issues/day ร— 1,800 tokens = 18,000 tokens/day **New Tiered Approach:** - Tier 1: 6 ร— 400 = 2,400 tokens - Tier 2: 2.5 ร— 650 = 1,625 tokens - Tier 3: 1.5 ร— 1,800 = 2,700 tokens - **Total: 6,725 tokens/day** **Savings: 63%** while maintaining quality and comprehensive coverage when needed ## Integration Points ### **Dev Agent Integration** ```yaml quality_issue_workflow: - execute_reality_audit - auto_remediation_triage # Smart tier assignment - apply_appropriate_fixes # Tier-specific approach - validate_resolution # Confirm issue resolved ``` ### **QA Agent Integration** ```yaml remediation_workflow: - assess_issue_complexity # Determine appropriate tier - provide_tiered_solution # Apply tier-specific remediation - track_resolution_success # Monitor effectiveness ``` ## Success Criteria - [ ] Smart triage classification (100-200 tokens) - [ ] Tier 1 quick fixes for 60% of issues (300-500 tokens each) - [ ] Tier 2 guided fixes for 25% of issues (500-800 tokens each) - [ ] Tier 3 full stories for 15% of complex issues (1500-2000+ tokens each) - [ ] 60-70% overall token savings compared to always using full remediation - [ ] Maintains quality standards across all tiers - [ ] Integration with existing quality framework This provides **intelligent remediation scaling** that matches solution complexity to issue complexity, maximizing efficiency while maintaining comprehensive coverage for complex problems!