Skip to content

Break circular dependencies #20

@gloomcheng

Description

@gloomcheng

Summary

Identify and resolve circular dependencies that require dynamic imports.

Current Problem

  • Line 201 in LineHandlers.js uses dynamic import to break circular dependency:
    const { getKeychainService } = await import('../../services/keychainService.js');
  • AgentRouter instantiates ResolutionIntelligence and ContactUnifier internally
  • MatterAgent instantiates ContextFusionEngine internally
  • These patterns create tight coupling and make testing difficult

Implementation

Strategy

  1. Extract shared interfaces - Create interface files that both modules can depend on
  2. Use events - Decouple cross-service communication via EventBus
  3. Use DI - Inject dependencies instead of importing/instantiating
  4. Lazy initialization - Defer dependency resolution where needed

Files to Analyze

  • src/ipc/handlers/LineHandlers.js - Dynamic import workaround
  • src/services/agents/AgentRouter.js - Internal instantiation
  • src/services/agents/MatterAgent.js - Internal instantiation

Tasks

  • Audit all dynamic imports in codebase
  • Extract shared interfaces
  • Refactor to use EventBus for cross-service communication
  • Replace dynamic imports with proper DI
  • Update dependency graph documentation

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions