Skip to content

refactor: Add plugin API abstraction layer #59

Description

@nigel-dev

Source

Audit report — Section 7: Technical Debt > Architecture

Description

MC directly uses the OpenCode plugin SDK APIs (client.session.prompt(), client.session.get(), hook registration, etc.) throughout the codebase without an abstraction layer. This couples MC tightly to the specific OpenCode SDK version and makes it impossible to:

  • Run MC logic in tests without the full plugin runtime
  • Port MC to other AI coding tool ecosystems
  • Mock the plugin API cleanly in unit tests

Current State

  • index.ts directly uses client.session.prompt(), client.session.get(), hook registration
  • notifications.ts, compaction.ts, commands.ts all depend directly on SDK types
  • No interface abstraction for the plugin SDK

Proposed Solution

  1. Define a PluginHost interface covering MC's SDK usage: notifications, hooks, session state, commands
  2. Implement OpenCodePluginHost wrapping the real SDK
  3. MC core logic depends on PluginHost, not the SDK directly
  4. Tests can use MockPluginHost
  5. Future: ClaudeCodePluginHost, CursorPluginHost, etc.

Priority

P3 — architectural improvement. Not blocking functionality, but improves testability and future portability.

Relationship to Other Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3: lowNice to have — polish, cleanup, or long-termenhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions