Skip to content

refactor(core): extract CLI logic into adapter pattern#242

Merged
jlia0 merged 1 commit intomainfrom
jlia0/adapter-model
Mar 20, 2026
Merged

refactor(core): extract CLI logic into adapter pattern#242
jlia0 merged 1 commit intomainfrom
jlia0/adapter-model

Conversation

@jlia0
Copy link
Collaborator

@jlia0 jlia0 commented Mar 19, 2026

Description

Extract provider-specific CLI invocation logic from invoke.ts into independent adapter modules. Each CLI backend (Claude, Codex, OpenCode) now implements a standardized AgentAdapter interface and auto-registers via a provider registry.

This refactoring reduces invoke.ts from ~400 to ~190 lines, improves testability, and simplifies adding new CLI backends—just create a new adapter file and call registerAdapter().

Changes

  • Created packages/core/src/adapters/ directory with 5 files:
    • types.ts — defines AgentAdapter interface and InvokeOptions
    • claude.ts, codex.ts, opencode.ts — adapter implementations for each CLI
    • index.ts — registry and auto-registration
  • Simplified invoke.ts by delegating all provider-specific logic to adapters
  • Exported AgentAdapter, InvokeOptions, getAdapter, registerAdapter from core

Testing

Existing tests pass without modification (adapters maintain the same behavior as the original inline code). No breaking changes to the invokeAgent API.

Co-Authored-By: Claude Haiku 4.5 noreply@anthropic.com

Simplify invokeAgent by moving provider-specific logic into independent adapter modules. Each CLI backend (Claude, Codex, OpenCode) now implements a standardized AgentAdapter interface and registers automatically via a provider registry.

This reduces invoke.ts from ~400 lines to ~190, improves testability, and makes it straightforward to add new CLI backends.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant