🔍 Duplicate Code Detected
Analysis of commit 2a1d0c8
Assignee: @copilot
Summary
Multiple prompt-step generator methods introduced for different workflow prompts share nearly identical control flow and rendering logic. Each method repeats the same guard checks and appendPromptStep/WritePromptTextToYAML pattern with only constant substitutions, creating five copies of a 15–18 line block.
Duplication Details
Pattern 1: Repeated prompt-step generator scaffolding
- Severity: Medium
- Occurrences: 5
- Locations:
pkg/workflow/edit_tool_prompt.go:8
pkg/workflow/playwright_prompt.go:8
pkg/workflow/github_context.go:7
pkg/workflow/temp_folder.go:8
pkg/workflow/xpia.go:7
- Code Sample:
appendPromptStep(yaml,
"Append <prompt> instructions to prompt",
func(y *strings.Builder, indent string) {
WritePromptTextToYAML(y, <PromptText>, indent)
},
"", // no condition
" ")
Impact Analysis
- Maintainability: Adding or adjusting prompt-step behavior requires editing five separate functions, increasing drift risk.
- Bug Risk: Future fixes to guard conditions or formatting could be applied inconsistently across copies.
- Code Bloat: Roughly 80–90 lines of boilerplate repeat without abstraction.
Refactoring Recommendations
-
Introduce shared helper
- Extract a utility like
generateStaticPromptStep(yaml, description, promptText, condition, guard) that encapsulates the guard logic and appendPromptStep call.
- Estimated effort: 2–3 hours to design helper, update call sites, and add coverage.
- Benefits: Single source of truth for prompt rendering, easier future additions, reduced risk of inconsistent guards.
-
Parameterize tool-based guards
- For tool-driven prompts, add a helper that checks tool availability (
requireTool(data, toolKey)) before invoking the shared generator.
- Benefits: Clarifies intent and reduces copy/pasted
if data.Tools == nil blocks.
Implementation Checklist
Analysis Metadata
- Analyzed Files: 5
- Detection Method: Serena semantic code analysis
- Commit: 2a1d0c8
- Analysis Date: 2025-02-14
AI generated by Duplicate Code Detector
🔍 Duplicate Code Detected
Analysis of commit 2a1d0c8
Assignee:
@copilotSummary
Multiple prompt-step generator methods introduced for different workflow prompts share nearly identical control flow and rendering logic. Each method repeats the same guard checks and
appendPromptStep/WritePromptTextToYAMLpattern with only constant substitutions, creating five copies of a 15–18 line block.Duplication Details
Pattern 1: Repeated prompt-step generator scaffolding
pkg/workflow/edit_tool_prompt.go:8pkg/workflow/playwright_prompt.go:8pkg/workflow/github_context.go:7pkg/workflow/temp_folder.go:8pkg/workflow/xpia.go:7Impact Analysis
Refactoring Recommendations
Introduce shared helper
generateStaticPromptStep(yaml, description, promptText, condition, guard)that encapsulates the guard logic andappendPromptStepcall.Parameterize tool-based guards
requireTool(data, toolKey)) before invoking the shared generator.if data.Tools == nilblocks.Implementation Checklist
Analysis Metadata