Skip to content

[duplicate-code] 🔍 Duplicate Code Detected #1850

@github-actions

Description

@github-actions

🔍 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

  1. 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.
  2. 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

  • Review duplication findings
  • Prioritize refactoring tasks
  • Create refactoring plan
  • Implement changes
  • Update tests
  • Verify no functionality broken

Analysis Metadata

  • Analyzed Files: 5
  • Detection Method: Serena semantic code analysis
  • Commit: 2a1d0c8
  • Analysis Date: 2025-02-14

AI generated by Duplicate Code Detector

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions