Conversation
…ove duplicates Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…ReportingConfig; address review comments Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot recompile |
There was a problem hiding this comment.
Pull request overview
This PR refactors pkg/workflow/ to eliminate structural duplication and improve code organization, addressing 8 of 10 issues identified by semantic analysis. The refactoring consolidates duplicate logic, extracts cross-engine helpers, and fixes an interface bypass pattern (including a duplicate *CodexEngine block).
Changes:
- Unified
missing_data.goandmissing_tool.gointo sharedmissing_issue_reporting.go(~260 lines eliminated) - Extracted firewall helpers (
generateSquidLogsUploadStep,generateFirewallLogParsingStep,defaultGetSquidLogsSteps) toengine_firewall_support.go - Added
GetFirewallLogsCollectionSteptoWorkflowExecutorinterface, replacing type-assertion chains with polymorphic calls - Extracted
shouldRewriteLocalhostToDockerandnoOpCacheMemoryRenderertomcp_config_utils.go - Removed duplicate
parseToolCallsfunction (78 lines) fromclaude_logs.go - Merged
safe_output_config.gointosafe_outputs_config.go
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/missing_issue_reporting.go |
New shared implementation for missing-data and missing-tool config/job building with type aliases for backward compatibility |
pkg/workflow/missing_data.go |
Reduced from ~163 to ~31 lines by delegating to shared functions |
pkg/workflow/missing_tool.go |
Reduced from ~163 to ~31 lines by delegating to shared functions |
pkg/workflow/engine_firewall_support.go |
Added 3 firewall-related helper functions extracted from copilot_installer.go and engine files |
pkg/workflow/copilot_installer.go |
Removed 2 firewall helper functions (moved to engine_firewall_support.go), cleaned up unused imports |
pkg/workflow/mcp_config_utils.go |
Added shouldRewriteLocalhostToDocker helper and noOpCacheMemoryRenderer no-op function |
pkg/workflow/codex_mcp.go |
Uses shouldRewriteLocalhostToDocker helper (2 call sites) |
pkg/workflow/copilot_mcp.go |
Uses shouldRewriteLocalhostToDocker helper |
pkg/workflow/mcp_config_custom.go |
Uses shouldRewriteLocalhostToDocker helper |
pkg/workflow/claude_mcp.go |
Uses noOpCacheMemoryRenderer, removed duplicate method |
pkg/workflow/gemini_mcp.go |
Uses noOpCacheMemoryRenderer, removed duplicate method |
pkg/workflow/claude_logs.go |
Removed 78-line duplicate parseToolCalls function, replaced call with parseToolCallsWithSequence |
pkg/workflow/claude_engine.go |
Uses defaultGetSquidLogsSteps helper |
pkg/workflow/codex_engine.go |
Uses defaultGetSquidLogsSteps helper |
pkg/workflow/copilot_logs.go |
Uses defaultGetSquidLogsSteps helper |
pkg/workflow/compiler_yaml_main_job.go |
Fixed duplicate *CodexEngine block by using polymorphic GetFirewallLogsCollectionStep interface method |
pkg/workflow/agentic_engine.go |
Added GetFirewallLogsCollectionStep to WorkflowExecutor interface and default implementation in BaseEngine |
pkg/workflow/safe_outputs_config.go |
Absorbed parseBaseSafeOutputConfig from deleted safe_output_config.go, added strings import |
pkg/workflow/safe_output_config.go |
Deleted (function moved to safe_outputs_config.go) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Recompiled all 161 workflow files — no lock file changes (output is identical to pre-refactoring, confirming the code changes don't affect workflow compilation). Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
safe_output_config.go(single function) intosafe_outputs_config.go; deleted thin fileparseToolCalls; call site now usesparseToolCallsWithSequence(sequence return value explicitly discarded with comment)shouldRewriteLocalhostToDockerhelper inmcp_config_utils.go; replaced 4 inline guard expressionsnoOpCacheMemoryRendererinmcp_config_utils.go; removed redundant engine methods from Claude and GeminigenerateSquidLogsUploadStep/generateFirewallLogParsingStepfromcopilot_installer.gotoengine_firewall_support.godefaultGetSquidLogsStepstoengine_firewall_support.go; all three engines delegate to itGetFirewallLogsCollectionSteptoWorkflowExecutorinterface +BaseEnginedefault; replaced 4-block type-switch (including duplicateCodexEnginecase) with single polymorphic callmissing_issue_reporting.gowith sharedIssueReportingConfig,buildIssueReportingJob,parseIssueReportingConfig; type aliases for backward compatibility; eachmissing_*.goslimmed to ~30 linesOriginal prompt
This section details on the original issue you should resolve
<issue_title>[refactor] Semantic Function Clustering Analysis: Duplicates, Misplaced Logic, and Fragmented Files in pkg/workflow</issue_title>
<issue_description>Automated semantic analysis of the
pkg/directory (563 non-test Go files across 18 packages, 280 inpkg/workflow/) identified 10 concrete refactoring opportunities. Findings are ordered by estimated impact.Summary
workflow, ~192 incli, 37 inparser, and smaller utility packages)Issue 1: Near-Duplicate Files —
missing_data.goandmissing_tool.goFiles:
pkg/workflow/missing_data.go,pkg/workflow/missing_tool.goProblem: These two ~163-line files are structurally identical. The only differences are token-level (variable name, log prefix, env var prefix, default title prefix string, script path). The struct definitions (
MissingDataConfig/MissingToolConfig) are identical except for a comment word. Theparse*Configandbuild*Jobfunctions share 100% of their control-flow logic and field-access patterns.Recommendation: Introduce a single generic config type (e.g.,
IssueReportingConfig) with a parameter struct covering the varying fields, and a single sharedbuildIssueReportingJob/parseIssueReportingConfigfunction. Type aliasesMissingDataConfig/MissingToolConfigcan remain for backward compatibility. Estimated elimination: ~120 lines of duplicated logic.Issue 2: Triplicated
GetSquidLogsStepsAcross Three Engine FilesFiles:
pkg/workflow/claude_engine.go(line 470)pkg/workflow/codex_engine.go(line 354)pkg/workflow/copilot_logs.go(line 450)Problem: All three
GetSquidLogsStepsimplementations are byte-for-byte identical except for the logger variable. All three callisFirewallEnabled,generateSquidLogsUploadStep, andgenerateFirewallLogParsingStepwith the same arguments and same conditional structure. Similarly,GetFirewallLogsCollectionStepis a no-op stub duplicated in bothclaude_engine.goandcodex_engine.go.Recommendation: Move a shared
DefaultGetSquidLogsSteps(workflowData *WorkflowData, log *logger.Logger) []GitHubActionStephelper toengine_firewall_support.go(which already exists for cross-engine firewall logic). Each engine calls it with its own logger, reducing three 18-line functions to three 3-line wrappers. Alternatively, promoteGetSquidLogsStepstoBaseEnginesince the logic is engine-agnostic.Issue 3: Near-Duplicate
RenderMCPConfiginclaude_mcp.goandgemini_mcp.goFiles:
pkg/workflow/claude_mcp.go(lines 12–69)pkg/workflow/gemini_mcp.go(lines 12–64)Problem: Diffing the two functions shows they differ only in receiver type, logger variable name, and one minor comment. The
MCPRendererOptionsstruct passed in both uses identical fields (IncludeCopilotFields: false, InlineArgs: false, Format: "json"). TheMCPToolRenderersstruct construction is completely parallel with the same eight function closures in the same order. (Note:copilot_mcp.golegitimately differs by usingIncludeCopilotFields: true, InlineArgs: true.)Recommendation: Extract a shared
renderJSONMCPConfigForEnginehelper that acceptsMCPRendererOptions, a config path string, and engine-specific overrides. Both Claude and Gemini engines call it with their specific logger. This can live inmcp_config_utils.go.Issue 4: Repeated
rewriteLocalhostGuard Expression (4+ Call Sites)Files:
pkg/workflow/codex_mcp.go(lines 172–174 and 195–197 — appears twice)pkg/workflow/copilot_mcp.go(lines 90–92)pkg/workflow/mcp_config_custom.go(lines 53–55)Problem: The following expression is repeated verbatim at 4 locations across 3 files, with an additional 14+ variant occurrences of the nil-guard chain across the package:
Recommendation: Add
shouldRewriteLocalhostToDocker(workflowData *WorkflowData) boolinmcp_config_utils.goorsandbox.go. All call sites replace the 3-line guard with a single readable predicate. This clarifies the semantics: firewall enabled = rewrite localhost.Issue 5: Misplaced Firewall Step Generators in
copilot_installer.goFile: `pkg/workflow/copilot_instal...
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.