Skip to content

HIGH: Massive code duplication across AI modules (32K+ LOC) #20

@sfloess

Description

@sfloess

Severity

High

Description

All 8 non-Claude AI modules contain 90%+ duplicated code from the Claude module. This represents approximately 32,000 lines of duplicated code across:

  • API client implementations
  • UI components (chat windows, panels)
  • Code completion providers
  • Action handlers
  • Settings panels
  • Utility classes

Affected Modules

  • ai/gemini/ - ~4,000 LOC duplicated from Claude
  • ai/chatgpt/ - ~4,000 LOC duplicated from Claude
  • ai/grok/ - ~4,000 LOC duplicated from Claude
  • ai/mistral/ - ~4,000 LOC duplicated from Claude
  • ai/perplexity/ - ~4,000 LOC duplicated from Claude
  • ai/cohere/ - ~4,000 LOC duplicated from Claude
  • ai/deepseek/ - ~4,000 LOC duplicated from Claude
  • ai/openrouter/ - ~4,000 LOC duplicated from Claude

Impact

  • DRY principle violation
  • Bug fixes must be applied 9 times
  • Inconsistent behavior across modules
  • Maintenance nightmare
  • Difficult to add new features

Recommended Solution

Create ai/common module with shared abstractions:

  1. Abstract Base Classes:

    • AbstractAIClient - HTTP client, conversation history, error handling
    • AbstractChatTopComponent - Chat UI, message rendering
    • AbstractCompletionProvider - Code completion logic
    • AbstractConfigPanel - Settings UI
  2. Shared Utilities:

    • AIClientFactory - Factory for creating clients
    • ConversationManager - Thread-safe conversation handling
    • RetryPolicy - Exponential backoff logic
    • StreamingResponseHandler - SSE/streaming handling
  3. Module Structure:

ai/
├── common/                    # NEW
│   ├── api/
│   │   ├── AbstractAIClient.java
│   │   └── ConversationManager.java
│   ├── ui/
│   │   └── AbstractChatTopComponent.java
│   └── completion/
│       └── AbstractCompletionProvider.java
├── claude/
│   └── extends common classes
├── gemini/
│   └── extends common classes
└── ...

Estimated Impact

Priority

High - Technical debt affecting maintainability

Metadata

Metadata

Assignees

No one assigned

    Labels

    ai-modulesAffects AI modulesarchitectureArchitecture and designcode-solve-in-progressIssue is being worked on by code-solve automationenhancementNew feature or requesthighHigh priority - fix soonrefactoringCode refactoring needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions