Repository navigation
Closed as not planned
Closed as not planned
Copy link
Description
🔍 Duplicate Code Detected: GitHub MCP Renderer Logic
Analysis of commit 7658c86
Assignee: @copilot
Summary
Rendering the GitHub MCP server configuration is implemented separately in the Copilot, Claude, Codex, and Custom engine files. Each version repeats the same remote/local branching, token precedence, and closing boilerplate with only minor option differences.
Duplication Details
Pattern: Repeated GitHub MCP rendering branches in engine renderers
- Severity: Medium
- Occurrences: 4
- Locations:
pkg/workflow/copilot_engine.go:398pkg/workflow/claude_engine.go:652pkg/workflow/codex_engine.go:479pkg/workflow/custom_engine.go:161
- Code Sample:
githubType := getGitHubType(githubTool) readOnly := getGitHubReadOnly(githubTool) toolsets := getGitHubToolsets(githubTool) yaml.WriteString(" \"github\": {\n") if githubType == "remote" { RenderGitHubMCPRemoteConfig(...) } else { RenderGitHubMCPDockerConfig(...) } if isLast { yaml.WriteString(" }\n") } else { yaml.WriteString(" },\n") }
Impact Analysis
- Maintainability: Any change to GitHub MCP rendering rules must be replicated four times, increasing the chance the engine implementations drift apart.
- Bug Risk: Fixes for token precedence or read-only handling can be missed in one engine, leading to subtle runtime differences.
- Code Bloat: Roughly 150 lines of near-identical logic inflate the workflow package and obscure true engine-specific behavior.
Refactoring Recommendations
-
Extract a shared GitHub MCP rendering helper
- Centralize the remote/local branching and token resolution in
engine_helpers.go(or a new helper) that accepts formatting options (JSON vs TOML, allowed tool handling, env passthrough). - Estimated effort: Medium (4–6h)
- Benefits: Single source of truth, easier future fixes, consistent behavior across engines.
- Centralize the remote/local branching and token resolution in
-
Model GitHub MCP config as a shared struct
- Populate a
GitHubMCPConfigstruct once per engine and pass it to format-specific writers (JSON/TOML) to eliminate repeatedyaml.WriteStringsequences. - Estimated effort: Medium (4h)
- Benefits: Clear separation between data gathering and rendering, unlocks unit tests on shared logic.
- Populate a
Implementation Checklist
- Review duplication findings
- Prioritize refactoring tasks
- Create refactoring plan
- Implement changes
- Update tests
- Verify no functionality broken
Analysis Metadata
- Analyzed Files: 4
- Detection Method: Serena semantic code analysis
- Commit: 7658c86
- Analysis Date: 2025-10-24T21:09:47Z
AI generated by Duplicate Code Detector
Activity
fix: prune stale gh-aw-actions entries from actions-lock.json after c…
Prune stale gh-aw-actions entries from actions-lock.json after compil…