AI Collaboration
12 min

Interactive Refactoring with AI: Ensuring Quality Through Questions and Confirmations

Learn how AI can detect contradictions and risks, asking questions to achieve safer and more efficient refactoring.

AI CollaborationRefactoringInteractive DevelopmentQuality ImprovementBest Practices

Why AI Should Ask Questions

Case from June 16, 2025: On a functioning Tips page, AI attempted a "fix" that broke data integrity. If AI had first asked "What do you think is the root cause of this error?", this problem could have been prevented.

5 Times When AI Should Ask Questions

1. When Finding Contradictions with Documentation

typescript
// 🤖 AI: "CLAUDE.md states 'always use design system',
//         but this component uses direct Tailwind classes.
//         Should I add it to the design system first?"

const Component = () => (
  <h1 className="text-3xl font-bold">Title</h1>  // Contradiction detected
)

// Human: "Yes, let's add it to the design system first"

2. When Changes Have Large Impact

bash
# 🤖 AI: "This change affects 23 files.
#         Should we proceed gradually or all at once?
#         Would you like to see the list of affected files?"

# Human: "Show me the list. Let's prioritize and go gradually"

3. When Finding Data Inconsistencies

javascript
// 🤖 AI: "index.json has 15 articles,
//         but the articles folder has 17 files.
//         Which is the correct state? Should I sync them?"

// Human: "File system is correct. Regenerate index.json"

4. When Performance Concerns Arise

typescript
// 🤖 AI: "This refactoring increases bundle size by 15%.
//         Should we consider code splitting? Or is this acceptable?"

// Human: "15% is too much. Analyze the main causes"

5. When Similar to Past Failure Patterns

javascript
// 🤖 AI: "Documentation shows a similar case where
//         index.json sync was broken.
//         Should we verify both individual files
//         and index.json before proceeding?"

// Human: "Right, I forgot about that case. Verify before proceeding"

Practical Example of Interactive Refactoring

Solving Category Error (Real Case)

typescript
// Situation: tips.categories.ai-development displayed without translation

// ❌ Traditional AI: Immediate "fix"
const categories = [
  { value: 'ai-development', label: t('categories.ai-development') }, // Added
]

// ✅ Question-based AI:
🤖 AI: "Category 'ai-development' is displayed as a translation key.
        I've investigated these possibilities:
        
        1. Missing category definition in TipsFilteredGrid → Confirmed, not defined
        2. Wrong category in article → Found 1 match
        3. Missing key in translation file → Key exists
        
        Based on grep search, #2 seems most likely.
        Should I change the category in 'ai-collaboration-confirmation-rule.json'
        from 'ai-development' to 'ai-collaboration'?"

Human: "Yes, the article category is wrong. Change it"

🤖 AI: "Understood. After changing, index.json needs syncing too.
        Should I run the rebuild-tips-index.js script?"

Human: "Yes, run it"

Implementing AI's "Questioning Power"

Prompt Template

typescript
const refactoringPrompt = `
You are a careful AI assistant with strong questioning skills.
During refactoring:

1. Always analyze and report impact before changes
2. Check for contradictions with documentation (CLAUDE.md, README, etc.)
3. Ask questions instead of making assumptions
4. Propose gradual execution plans

Always ask when:
- Affecting 5+ files
- Changing data structures (JSON, DB, etc.)
- Potential performance impact
- Similar to past failure patterns
- Changes involve business logic

When asking questions:
- Include investigation results
- Present multiple options
- Explain recommendations with reasons
`;

Implementation: Intelligent Confirmation System

javascript
class RefactoringAssistant {
  async analyzeImpact(change) {
    const impact = {
      files: await this.findAffectedFiles(change),
      performance: await this.estimatePerformanceImpact(change),
      dataIntegrity: await this.checkDataConsistency(change),
      documentation: await this.checkDocumentationConflicts(change)
    };
    
    return this.generateQuestions(impact);
  }
  
  generateQuestions(impact) {
    const questions = [];
    
    if (impact.files.length > 5) {
      questions.push({
        type: 'scope',
        message: `This change affects ${impact.files.length} files. Proceed gradually?`,
        options: ['Gradual execution', 'Bulk execution', 'View affected files']
      });
    }
    
    if (impact.dataIntegrity.issues.length > 0) {
      questions.push({
        type: 'data',
        message: 'Data inconsistencies detected:\n' + impact.dataIntegrity.issues.join('\n'),
        options: ['Auto-fix', 'Manual review', 'Show details']
      });
    }
    
    return questions;
  }
}

Team Collaboration

Sharing AI Question Logs

markdown
## AI Question Log (2025-06-16)

### Q1: About category inconsistency
Situation: tips.categories.ai-development displayed
AI Question: "Should I fix category definition or article category?"
Human Answer: "Fix article category"
Result: ✅ Success
Learning: Translation key errors often originate from article side

### Q2: About index.json sync
Situation: After editing individual files
AI Question: "Should I update index.json too?"
Human Answer: "Yes, auto-update with script"
Result: ✅ Success
Learning: Tips/News changes always need index.json sync

Accumulating Best Practices

typescript
// AI learning database
const refactoringPatterns = {
  'category-error': {
    symptoms: ['Translation key displayed'],
    questions: ['Definition side or usage side?', 'Did you grep for usage?'],
    solutions: ['Fix article category', 'Add category definition'],
    preferred: 0 // Prefer first solution
  },
  
  'data-sync': {
    symptoms: ['index.json and individual files mismatch'],
    questions: ['Which is correct state?', 'Sync with script?'],
    solutions: ['Run rebuild-index.js', 'Manual fix'],
    preferred: 0
  }
};

From Defense to Offense: Proactive Quality Management

Traditional Approach (Defense)

- Follow checklists - Careful step-by-step - Human makes all decisions - Deal with problems after they occur

New Approach (Offense)

- AI actively detects contradictions - Asks questions immediately when in doubt - Explores optimal solutions through dialogue - Learns from past experiences - Prevents problems before they happen

Example of Ideal Collaboration

Human: "Fix this error"

🤖 AI: "I've analyzed the error. There are 3 solutions:
        1. Add category to component (easy but not fundamental)
        2. Fix article category (root solution)
        3. Add key to translation file (likely unnecessary)
        
        Past cases show method 1 caused side effects.
        I recommend method 2. What do you think?"

Human: "Go with method 2. What's the impact?"

🤖 AI: "One article file and index.json.
        I'll fix the article first, then update index.json
        with the regeneration script. Shall I proceed?"

Human: "OK, go ahead"

🤖 AI: "Completed. Final check:
        - Article category: ✅ Fixed
        - index.json: ✅ Synced
        - Browser display: Please verify"

Summary: AI's Questioning Power Protects Quality

By giving AI "questioning power":

  1. Problem Prevention: Discover potential issues before execution
  2. Knowledge Accumulation: Q&A logs become knowledge base
  3. Efficient Collaboration: Human input only where needed
  4. Quality Improvement: Verification from multiple perspectives

The key is to use AI not just as an executor, but as a thoughtful partner.