refactor: extract AgentProvider abstraction for multi-provider support - #130
Merged
Conversation
Extract all Claude Code-specific logic (binary resolution, CLI flag building, env var setup, startup watcher) from sessions.ts into a providers/claude-code.ts module implementing the AgentProvider interface. sessions.ts now delegates to the provider registry for spawn configuration, making it provider-agnostic. This is the prerequisite (Phase 0) for adding Codex CLI and Gemini CLI as alternative agent runtimes. Key changes: - Expand AgentProvider interface with resolveBinary(), buildArgs(), buildEnv(), attachStartupWatcher(), and ProviderCapabilities - Add PtyHandle abstraction to avoid node-pty dependency in core package - Add ResolvedSpawnOptions for pre-resolved spawn configuration - Create provider registry with getProvider() and getAllProviders() - Net removal of ~260 lines from sessions.ts monolith Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
nox-0x
approved these changes
Apr 13, 2026
nox-0x
left a comment
Collaborator
There was a problem hiding this comment.
Clean abstraction — well-structured provider interface, sessions.ts is now cleanly provider-agnostic, and all CC-specific logic is correctly extracted. The attachStartupWatcher improvements (agent labels, ptyDead guard, cleaner console output) are a meaningful upgrade. No blocking issues. LGTM.
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.
Summary
sessions.tsintoproviders/claude-code.tsimplementing theAgentProviderinterfaceproviders/index.ts) withgetProvider()/getAllProviders()— sessions.ts delegates to the provider instead of hardcoding CC flagsAgentProviderinterface withresolveBinary(),buildArgs(),buildEnv(),attachStartupWatcher(), andProviderCapabilitiestypePtyHandleabstraction to keepnode-ptydependency out of the core packageResolvedSpawnOptionstype for pre-resolved spawn configuration passed to providersThis is Phase 0 of multi-provider support (Codex CLI + Gemini CLI). Pure refactor — zero behavior change, all 70 tests pass.
Architecture
Why this matters
sessions.tswas an 830-line monolith with CC-specific flags hardcoded throughout. Adding Codex or Gemini support would have required forking the entire function. Now, adding a new provider means creating a single file that implementsAgentProvider— the orchestration layer is shared.Research backing this:
docs/research/multi-provider-support.md(POC validated with both Codex v0.118.0 and Gemini v0.30.0).Test plan
make checkpasses (lint + typecheck + 70/70 tests)attachStartupWatcherexpectChannelslogic (caught by code-reviewer)buildArgs(caught by code-reviewer)🤖 Generated with Claude Code