-
Notifications
You must be signed in to change notification settings - Fork 28
Closed
Description
🔍 Duplicate Code Detected: Staged Agent Output Processing Blocks
Analysis of commit 5463e38
Assignee: @copilot
Summary
Multiple workflow action handlers duplicate the same staged-mode guard and agent-output filtering logic. Each module reimplements the same steps to load agent_output.json, short-circuit when no matching items exist, and render staged previews, which creates a large maintenance surface area.
Duplication Details
Pattern: Repeated staged-mode branching and agent output filtering
- Severity: Medium
- Occurrences: 4 confirmed (several more likely follow the same pattern)
- Locations:
pkg/workflow/js/create_issue.cjs:10pkg/workflow/js/create_discussion.cjs:8pkg/workflow/js/update_issue.cjs:7pkg/workflow/js/add_comment.cjs:90
- Code Sample:
const result = loadAgentOutput(); if (!result.success) { return; } const items = result.items.filter(item => item.type === "create_issue"); if (items.length === 0) { core.info("No create-issue items found in agent output"); return; } if (isStaged) { await generateStagedPreview({ title: "Create Issues", description: "The following issues would be created if staged mode was disabled:", items, renderItem: /* custom renderer */ }); return; }
Impact Analysis
- Maintainability: Fixes or enhancements to staged-mode behavior must be edited in every action module, making it easy to miss a caller and introduce inconsistent behavior.
- Bug Risk: Any changes to the staged preview contract or agent output schema require synchronized updates across files, increasing the chance of divergent logic and regressions.
- Code Bloat: The repeated 30–40 line blocks inflate the codebase and obscure the action-specific logic.
Refactoring Recommendations
-
Extract a shared helper
- Centralize staged-mode guarding, item filtering, and summary generation into a reusable function (e.g.,
processAgentOutputItems({ type, stagedRenderer, liveHandler })). - Estimated effort: Medium (coordinate shared callback signatures for item-specific behavior).
- Benefits: Single point for staged-mode logic, easier schema updates, smaller modules.
- Centralize staged-mode guarding, item filtering, and summary generation into a reusable function (e.g.,
-
Unify output initialization
- Provide a helper to initialize standard
core.setOutputdefaults for these handlers. - Estimated effort: Low.
- Benefits: Reduces boilerplate and risk of missing an output when new handlers are added.
- Provide a helper to initialize standard
Implementation Checklist
- Review duplication findings
- Prioritize refactoring tasks
- Create refactoring plan
- Implement changes
- Update tests
- Verify no functionality broken
Analysis Metadata
- Analyzed Files: 4 (create_issue.cjs, create_discussion.cjs, update_issue.cjs, add_comment.cjs)
- Detection Method: Serena semantic code analysis (manual inspection of staged-mode helpers)
- Commit: 5463e38
- Analysis Date: 2025-11-13
AI generated by Duplicate Code Detector
Copilot