Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 24, 2026

The CodingAgentEngine interface contained 18 methods mixing unrelated concerns (identity, capabilities, workflow execution, MCP configuration, logging, security), forcing all implementations to inherit the entire surface area.

Changes

Interface Segregation

  • Split into 6 focused interfaces:
    • Engine: Core identity (4 methods)
    • CapabilityProvider: Feature detection (6 methods)
    • WorkflowExecutor: Workflow compilation (3 methods)
    • MCPConfigProvider: MCP configuration (1 method)
    • LogParser: Log analysis (3 methods)
    • SecurityProvider: Security features (2 methods)
  • CodingAgentEngine remains as composite interface (backward compatible)

Usage Pattern

// Before: forced to accept full interface
func compile(engine CodingAgentEngine) { ... }

// After: depend only on what you need
func checkCapabilities(cp CapabilityProvider) { ... }
func generateSteps(we WorkflowExecutor) { ... }
func parseMetrics(lp LogParser) { ... }

Implementation

  • All engines embed BaseEngine which provides default implementations
  • Engines override specific methods as needed
  • No changes required to existing engine implementations

Bug Fix

  • CustomEngine.GetRequiredSecretNames() now returns empty slice instead of nil

Testing

  • Added comprehensive interface composition tests
  • Validates all engines implement all sub-interfaces
  • Demonstrates usage of specific interfaces
Original prompt

This section details on the original issue you should resolve

<issue_title>[Code Quality] Refactor CodingAgentEngine interface using Interface Segregation Principle</issue_title>
<issue_description>## Description

The CodingAgentEngine interface contains 18 methods that mix multiple unrelated concerns (metadata, capabilities, workflow, rendering, parsing, security), violating the Interface Segregation Principle and Single Responsibility Principle. This forces all implementations to implement or inherit all methods, making testing difficult and adding new engine types harder.

Background

Identified during Sergo analysis on 2026-01-23 (discussion #11477). The interface has grown from 16 methods to 18 methods (+12.5%) in just 5 days, indicating continued bloat.

Current state: Single monolithic interface with 18 methods
Trend: Growing worse (16 methods on 2026-01-18 → 18 methods on 2026-01-23)
Impact: Tight coupling, difficult testing, hard to add new engines

Files Affected

  • pkg/workflow/agentic_engine.go:19-81 - Interface definition
  • pkg/workflow/claude_engine.go:14-16 - ClaudeEngine implementation
  • pkg/workflow/copilot_engine.go:25-27 - CopilotEngine implementation
  • pkg/workflow/custom_engine.go - CustomEngine implementation
  • pkg/workflow/codex_engine.go - CodexEngine implementation
  • 90+ files importing the workflow package

Suggested Changes

Split into focused interfaces using composition:

// Core identity - required by all
type Engine interface {
    GetID() string
    GetDisplayName() string
    GetDescription() string
    IsExperimental() bool
}

// Capability detection - compose as needed
type CapabilityProvider interface {
    SupportsToolsAllowlist() bool
    SupportsHTTPTransport() bool
    SupportsMaxTurns() bool
    SupportsWebFetch() bool
    SupportsWebSearch() bool
    SupportsFirewall() bool
}

// Workflow execution - required for compilation
type WorkflowExecutor interface {
    GetInstallationSteps(*WorkflowData) []GitHubActionStep
    GetExecutionSteps(*WorkflowData, string) []GitHubActionStep
    GetDeclaredOutputFiles() []string
}

// MCP configuration - optional
type MCPConfigRenderer interface {
    RenderMCPConfig(*strings.Builder, map[string]any, []string, *WorkflowData)
}

// Log parsing - optional
type LogParser interface {
    ParseLogMetrics(string, bool) LogMetrics
    GetLogParserScriptId() string
    GetLogFileForParsing() string
}

// Security - optional
type SecurityProvider interface {
    GetDefaultDetectionModel() string
    GetRequiredSecretNames(*WorkflowData) []string
}

// Composite for backward compatibility
type CodingAgentEngine interface {
    Engine
    CapabilityProvider
    WorkflowExecutor
    MCPConfigRenderer
    LogParser
    SecurityProvider
}

Implementation Steps

  1. Define new focused interfaces
  2. Update engine implementations to use composition
  3. Refactor EngineRegistry to accept Engine interface
  4. Update call sites to use specific interfaces
  5. Add type assertions for optional capabilities
  6. Run existing tests for backward compatibility
  7. Add tests for new interface compositions

Success Criteria

  • 6 focused interfaces created (Engine, CapabilityProvider, WorkflowExecutor, MCPConfigRenderer, LogParser, SecurityProvider)
  • All engine implementations updated to use composition
  • Call sites use specific interfaces where appropriate
  • Backward compatibility maintained via composite interface
  • All tests pass
  • New tests added for interface compositions
  • make agent-finish passes

Priority

High - Architectural improvement that prevents further bloat

Estimated effort: Large (4-6 hours, affects 90+ files)

Source

Extracted from Sergo Interface Segregation analysis discussion githubnext/gh-aw#11477

Analysis quote:

"##### 1. CodingAgentEngine Interface Segregation Principle Violation

The CodingAgentEngine interface contains 18 methods that mix multiple unrelated concerns...

Impact:

  • Forces all implementations to implement or inherit all methods
  • Violates Single Responsibility Principle
  • Makes testing difficult (must mock all 18 methods)
  • Hard to add new engine types with different capability sets
  • Tight coupling - changes to one concern affect all implementers

Trend: Getting worse! Was 16 methods on 2026-01-18, now 18 methods (+12.5% growth)."

AI generated by Discussion Task Miner - Code Quality Improvement Agent

  • expires on Feb 6, 2026, 2:07 PM UTC

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits January 24, 2026 07:15
…ciple

- Define 6 focused interfaces: Engine, CapabilityProvider, WorkflowExecutor, MCPConfigProvider, LogParser, SecurityProvider
- CodingAgentEngine remains as composite interface for backward compatibility
- BaseEngine provides default implementations for all methods
- All existing engines (Copilot, Claude, Codex, Custom) work without changes
- Add comprehensive tests validating interface segregation
- Fix custom engine to return empty slice instead of nil for secrets
- Add detailed architecture documentation with usage patterns

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
- Remove redundant type assertions
- Use require.NoError for critical error checks
- All interface segregation tests pass

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor CodingAgentEngine interface for better modularity Refactor CodingAgentEngine using Interface Segregation Principle Jan 24, 2026
Copilot AI requested a review from pelikhan January 24, 2026 07:28
@pelikhan pelikhan marked this pull request as ready for review January 24, 2026 10:35
@pelikhan pelikhan merged commit 3627d27 into main Jan 24, 2026
118 checks passed
@pelikhan pelikhan deleted the copilot/refactor-coding-agent-engine-interface branch January 24, 2026 10:39
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.

[Code Quality] Refactor CodingAgentEngine interface using Interface Segregation Principle

2 participants