refactor(core): extract CLI logic into adapter pattern#242
Merged
Conversation
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>
This was referenced Mar 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Extract provider-specific CLI invocation logic from
invoke.tsinto independent adapter modules. Each CLI backend (Claude, Codex, OpenCode) now implements a standardizedAgentAdapterinterface and auto-registers via a provider registry.This refactoring reduces
invoke.tsfrom ~400 to ~190 lines, improves testability, and simplifies adding new CLI backends—just create a new adapter file and callregisterAdapter().Changes
packages/core/src/adapters/directory with 5 files:types.ts— definesAgentAdapterinterface andInvokeOptionsclaude.ts,codex.ts,opencode.ts— adapter implementations for each CLIindex.ts— registry and auto-registrationinvoke.tsby delegating all provider-specific logic to adaptersAgentAdapter,InvokeOptions,getAdapter,registerAdapterfrom coreTesting
Existing tests pass without modification (adapters maintain the same behavior as the original inline code). No breaking changes to the
invokeAgentAPI.Co-Authored-By: Claude Haiku 4.5 noreply@anthropic.com