Skip to content

refactor: extract shared utilities from duplicated code patterns#211

Merged
SDSLeon merged 3 commits into
masterfrom
devin/1781907375-refactor-shared-utilities
Jun 21, 2026
Merged

refactor: extract shared utilities from duplicated code patterns#211
SDSLeon merged 3 commits into
masterfrom
devin/1781907375-refactor-shared-utilities

Conversation

@devin-ai-integration

Copy link
Copy Markdown
Contributor

Summary

Consolidates six duplicated code patterns across 18 files into shared utilities. Net -24 lines (203 added, 227 removed).

Renderer — composer controls:

  • approvalPolicyDropdown() and standardPlanApprovalControls() added to composerControlBuilders.tsx. The identical plan-toggle + approval-dropdown combo in antigravity, commandcode, and gemini collapses to a one-liner: (input) => standardPlanApprovalControls(input). Claude uses approvalPolicyDropdown() for its filtered-policies variant.

Renderer — utility-task registries:

  • createUtilityTaskRegistry() factory replaces three copy-pasted registry blocks (commit-gen, title-gen, conflict-resolver) in ProviderIcon.tsx. Each registry is now 3 const assignments instead of 3 functions + a Map.

Shared — error message:

  • toErrorMessage(error: unknown): string extracted to src/shared/errorMessage.ts. Was duplicated verbatim in commitGen.ts and titleGen.ts; the error 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 to base/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 to browserMcp/index.ts. Replaces the identical 2-line WSL-guard + fallback-resolve pattern across all 5 provider mcpBrowser.ts files (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 typecheck
  • pnpm run lint
  • pnpm run fmt:check
  • pnpm run test
  • Not run; reason: native modules (better-sqlite3, node-pty) require electron-rebuild which isn't available in CI-less dev setup. Tests will run in CI.

Screenshots

No UI changes.

Linked issue

N/A

Link to Devin session: https://app.devin.ai/sessions/9952519ee5d34740a606b98f6d871955
Requested by: @SDSLeon

@devin-ai-integration devin-ai-integration Bot requested a review from SDSLeon as a code owner June 19, 2026 22:27
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lightcode-landing Ready Ready Preview, Comment Jun 21, 2026 5:43am

SDSLeon and others added 2 commits June 20, 2026 04:42
- 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>
@devin-ai-integration devin-ai-integration Bot force-pushed the devin/1781907375-refactor-shared-utilities branch from 9c98dcc to f16b001 Compare June 20, 2026 04:42
@SDSLeon SDSLeon merged commit c4f9d35 into master Jun 21, 2026
6 checks passed
@SDSLeon SDSLeon deleted the devin/1781907375-refactor-shared-utilities branch June 21, 2026 05:52
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