refactor: extract shared utilities from duplicated code patterns#211
Merged
Conversation
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- Extract toErrorMessage() to src/shared/errorMessage.ts (was duplicated in commitGen.ts and titleGen.ts) - Add approvalPolicyDropdown() and standardPlanApprovalControls() builders to composerControlBuilders.tsx - Simplify antigravity, commandcode, and gemini provider registrations to one-liner using standardPlanApprovalControls - Use approvalPolicyDropdown() in Claude's composer controls - Replace 3 identical utility-task registry blocks with createUtilityTaskRegistry() factory in ProviderIcon.tsx - Extract detectTerminalStatusFromHints() to base/terminalHints.ts (shared by antigravity + commandcode terminal detection) - Extract resolveOrFallbackBrowserMcpConfig() to browserMcp/index.ts (shared guard across 5 provider mcpBrowser files) Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
9c98dcc to
f16b001
Compare
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
Consolidates six duplicated code patterns across 18 files into shared utilities. Net -24 lines (203 added, 227 removed).
Renderer — composer controls:
approvalPolicyDropdown()andstandardPlanApprovalControls()added tocomposerControlBuilders.tsx. The identical plan-toggle + approval-dropdown combo in antigravity, commandcode, and gemini collapses to a one-liner:(input) => standardPlanApprovalControls(input). Claude usesapprovalPolicyDropdown()for its filtered-policies variant.Renderer — utility-task registries:
createUtilityTaskRegistry()factory replaces three copy-pasted registry blocks (commit-gen, title-gen, conflict-resolver) inProviderIcon.tsx. Each registry is now 3constassignments instead of 3 functions + aMap.Shared — error message:
toErrorMessage(error: unknown): stringextracted tosrc/shared/errorMessage.ts. Was duplicated verbatim incommitGen.tsandtitleGen.ts; theerror instanceof Error ? error.message : String(error)idiom appears ~100× across the codebase — future cleanup can import this utility incrementally.Supervisor — terminal status detection:
detectTerminalStatusFromHints(text, strongHints, fallbackIdleHints)added tobase/terminalHints.ts. Antigravity and commandcode terminal detectors now supply only their hint tables and call this shared function instead of duplicating the strong→fallback→corroborate logic.Supervisor — browser MCP config guard:
resolveOrFallbackBrowserMcpConfig(location, browserMcp?)added tobrowserMcp/index.ts. Replaces the identical 2-line WSL-guard + fallback-resolve pattern across all 5 providermcpBrowser.tsfiles (claude, codex, gemini, opencode, acp).Motivation
Reduces maintenance burden and inconsistency risk across provider adapters. All extractions are provider-agnostic: providers supply data (hint tables, config patches, policy lists) while shared utilities own the structural logic.
Testing
pnpm run typecheckpnpm run lintpnpm run fmt:checkpnpm run testScreenshots
No UI changes.
Linked issue
N/A
Link to Devin session: https://app.devin.ai/sessions/9952519ee5d34740a606b98f6d871955
Requested by: @SDSLeon