Overview
Semantic analysis found a repeated input-schema construction block across three Go functions that generate MCP tool definitions. The duplication is substantial (>60 lines each), and a behavior change in one function is likely to drift from the others.
Critical Findings
- Pattern: JSON schema property/required generation from workflow/tool input definitions
- Severity: Medium
- Occurrences: 3
- Threshold check: Exceeds both criteria (>10 duplicated lines and 3+ similar instances)
Duplication Locations
pkg/workflow/safe_outputs_call_workflow.go (generateCallWorkflowTool, lines 88-147)
pkg/workflow/safe_outputs_dispatch.go (generateDispatchWorkflowTool, lines 121-180)
pkg/workflow/dispatch_repository.go (generateDispatchRepositoryTool, lines 151-208)
Representative duplicated block (logic shape)
for inputName, inputDef := range workflowInputs {
inputDefMap, ok := inputDef.(map[string]any)
if !ok {
continue
}
inputType := "string"
inputDescription := ...
inputRequired := false
if desc, ok := inputDefMap["description"].(string); ok && desc != "" {
inputDescription = desc
}
if req, ok := inputDefMap["required"].(bool); ok {
inputRequired = req
}
if typeStr, ok := inputDefMap["type"].(string); ok {
switch typeStr {
case "number":
inputType = "number"
case "boolean":
inputType = "boolean"
case "choice":
inputType = "string"
if options, ok := inputDefMap["options"].([]any); ok && len(options) > 0 {
// enum + required handling
continue
}
case "environment":
inputType = "string"
}
}
// default + properties + required handling
}
Impact
- Maintainability: Bug fixes or schema updates require touching 3 sites with subtle differences.
- Behavior drift risk: Type mapping/default/required handling can diverge.
- Code bloat: Repeated branching and map wiring obscures the core intent of each generator.
Refactoring Recommendation
- Extract shared helper in
pkg/workflow/ (e.g., build_input_schema.go):
- Input:
map[string]any definitions + description callback/options.
- Output:
properties map[string]any, required []string.
- Preserve current special cases (choice enum/default handling).
- Keep generator-specific metadata local:
_workflow_name, _call_workflow_name, _dispatch_repository_tool, and description text should remain in their owning function.
- Add targeted tests for helper once:
- Type mapping for
string|number|boolean|choice|environment.
- Required sorting behavior and default propagation.
- Invalid input-def shape (
!map[string]any) skip behavior.
Implementation Checklist
Analysis Metadata
- Analyzed files: 932 eligible
.go/.cjs files (excluding tests and workflows)
- Method: Serena semantic analysis + structural duplicate scan
- Commit:
87085b3477d30beea73e9e5668ff9a9b3224a6d5
- Workflow run: §24281836678
- Triggered by:
@pelikhan
Generated by Duplicate Code Detector · ◷
Overview
Semantic analysis found a repeated input-schema construction block across three Go functions that generate MCP tool definitions. The duplication is substantial (>60 lines each), and a behavior change in one function is likely to drift from the others.
Critical Findings
Duplication Locations
pkg/workflow/safe_outputs_call_workflow.go(generateCallWorkflowTool, lines 88-147)pkg/workflow/safe_outputs_dispatch.go(generateDispatchWorkflowTool, lines 121-180)pkg/workflow/dispatch_repository.go(generateDispatchRepositoryTool, lines 151-208)Representative duplicated block (logic shape)
Impact
Refactoring Recommendation
pkg/workflow/(e.g.,build_input_schema.go):map[string]anydefinitions + description callback/options.properties map[string]any,required []string._workflow_name,_call_workflow_name,_dispatch_repository_tool, and description text should remain in their owning function.string|number|boolean|choice|environment.!map[string]any) skip behavior.Implementation Checklist
Analysis Metadata
.go/.cjsfiles (excluding tests and workflows)87085b3477d30beea73e9e5668ff9a9b3224a6d5@pelikhan