# Task ID: 14
# Title: Implement Semantic File Prioritization
# Status: deferred
# Dependencies: 11
# Priority: low
# Description: Develop semantic analysis capabilities to intelligently prioritize files based on content relevance to the current task.
# Details:
Create a SemanticAnalyzer class to analyze file content and determine relevance:

```typescript
export interface FileRelevanceScore {
  filePath: string;
  score: number;
  reason: string;
}

export class SemanticAnalyzer {
  private activeFile?: string;
  private activeFileContent?: string;
  private stopwords: Set<string>;
  
  constructor() {
    // Common programming stopwords
    this.stopwords = new Set([
      'the', 'and', 'a', 'to', 'of', 'is', 'in', 'that', 'it', 'with',
      'for', 'as', 'be', 'this', 'on', 'not', 'or', 'by', 'at', 'from'
    ]);
  }
  
  public setActiveFile(filePath: string, content: string): void {
    this.activeFile = filePath;
    this.activeFileContent = content;
  }
  
  public analyzeRelevance(files: FileData[]): FileRelevanceScore[] {
    if (!this.activeFile || !this.activeFileContent) {
      // Without an active file, we can't determine relevance
      return files.map(file => ({
        filePath: file.filePath,
        score: 1, // Default score
        reason: 'No active file for comparison'
      }));
    }
    
    // Extract keywords from active file
    const activeKeywords = this.extractKeywords(this.activeFileContent);
    
    return files.map(file => {
      // Skip the active file itself
      if (file.filePath === this.activeFile) {
        return {
          filePath: file.filePath,
          score: 10, // Highest score for active file
          reason: 'Active file'
        };
      }
      
      // Calculate relevance based on keyword overlap
      const fileKeywords = this.extractKeywords(file.content);
      const commonKeywords = this.findCommonKeywords(activeKeywords, fileKeywords);
      
      // Calculate score based on common keywords and file path similarity
      let score = commonKeywords.length / Math.max(1, activeKeywords.length) * 5;
      
      // Boost score for files in the same directory
      if (path.dirname(file.filePath) === path.dirname(this.activeFile)) {
        score += 2;
      }
      
      // Boost score for files with similar names
      const activeBasename = path.basename(this.activeFile, path.extname(this.activeFile));
      const fileBasename = path.basename(file.filePath, path.extname(file.filePath));
      if (fileBasename.includes(activeBasename) || activeBasename.includes(fileBasename)) {
        score += 1;
      }
      
      return {
        filePath: file.filePath,
        score,
        reason: commonKeywords.length > 0 ? 
          `Common keywords: ${commonKeywords.slice(0, 5).join(', ')}` : 
          'No common keywords'
      };
    });
  }
  
  private extractKeywords(content: string): string[] {
    // Simple keyword extraction - split by non-alphanumeric chars and filter stopwords
    const words = content.toLowerCase()
      .split(/[^a-zA-Z0-9_]/) // Split by non-alphanumeric chars
      .filter(word => word.length > 2) // Filter short words
      .filter(word => !this.stopwords.has(word)); // Filter stopwords
    
    // Count word frequencies
    const wordCounts = new Map<string, number>();
    for (const word of words) {
      wordCounts.set(word, (wordCounts.get(word) || 0) + 1);
    }
    
    // Sort by frequency and return top keywords
    return Array.from(wordCounts.entries())
      .sort((a, b) => b[1] - a[1]) // Sort by frequency (descending)
      .slice(0, 100) // Take top 100 keywords
      .map(entry => entry[0]); // Extract just the words
  }
  
  private findCommonKeywords(keywords1: string[], keywords2: string[]): string[] {
    const set1 = new Set(keywords1);
    return keywords2.filter(keyword => set1.has(keyword));
  }
}
```

Implement keyword extraction and frequency analysis to identify important terms in files. Add support for programming language-specific analysis (variable names, function calls, imports). Implement similarity scoring between files based on content overlap. Add support for directory structure analysis to identify related files. Integrate with the ContextWindowManager to prioritize semantically relevant files.

# Test Strategy:
1. Test keyword extraction with various file types
2. Verify relevance scoring with different file relationships
3. Test with large codebases to ensure performance
4. Verify language-specific analysis works correctly
5. Test integration with context window management
