-
Notifications
You must be signed in to change notification settings - Fork 46
[refactor] Phase 1: Consolidate validation helpers, centralize expression patterns, standardize MCP naming #11778
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ame files for consistency Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…e helpers Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor code organization and reduce duplication in Go package
[refactor] Phase 1: Consolidate validation helpers, centralize expression patterns, standardize MCP naming
Jan 25, 2026
Contributor
|
@copilot merge main, recompile |
…ot/refactor-semantic-function-analysis
Contributor
Author
Contributor
|
@copilot merge main, format, lint go |
…ot/refactor-semantic-function-analysis
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Contributor
Author
This was referenced Jan 25, 2026
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Phase 1: Quick Wins - Semantic Function Clustering Refactoring ✅
Goals
Implement high-impact, low-risk refactoring improvements identified in the semantic analysis:
Implementation Complete
Step 1: Create
pkg/workflow/validation_helpers.gowith common validation patternsfileExistshelper (actively used by 5 files)fileExistsfrom dispatch_workflow_validation.goStep 2: Create
pkg/workflow/expression_patterns.gowith centralized regexStep 3: Rename
permissions_validator.gotopermissions_validation.goStep 4: Standardize MCP file naming (mcp-config-* → mcp_config_*)
Step 5: Testing and Validation
Step 6: Merge main and maintenance
make fmtmake lint- zero issuesChanges Completed
✅ validation_helpers.go: Created with fileExists helper consolidating duplicate code
✅ validation_helpers_test.go: Comprehensive test coverage (exists)
✅ expression_patterns.go: 12 centralized regex patterns
✅ expression_patterns_test.go: Comprehensive test coverage with formatting
✅ permissions_validation.go: Renamed from permissions_validator.go
✅ 6 MCP config files: Standardized naming convention
✅ dispatch_workflow_validation.go: Removed duplicate fileExists
✅ Merged main branch: Successfully integrated all latest changes
✅ Formatted & Linted: All code properly formatted and validated
Test Coverage Summary
Impact Summary
Code Quality Improvements:
Foundation for Phase 2:
Success Criteria - All Met ✅
✅ Consistent naming convention across all MCP files
✅ Single source of truth for expression patterns
✅ fileExists helper consolidating duplicate code
✅ All tests building without errors
✅ All linters passing with zero issues
✅ Comprehensive test coverage for new code
✅ Successfully merged with main branch (2x)
✅ All code formatted per project standards
✅ All Go linting passing
Phase 1 Summary
Completed in 6 commits:
Ready for Phase 2:
The foundation is now in place for the broader refactoring work outlined in the original issue. Phase 2 will implement the remaining validation helpers and update the 32 validation files to use them, eliminating the 70+ remaining duplicate validation patterns.
No breaking changes - all existing functionality preserved and verified with main branch merge.
Original prompt
This section details on the original issue you should resolve
<issue_title>[refactor] Semantic Function Clustering Analysis - Code Organization and Duplication</issue_title>
<issue_description>Comprehensive semantic analysis of the Go codebase in
pkg/identifying function clustering patterns, duplicate code, outlier functions, and refactoring opportunities to improve code organization and maintainability.Executive Summary
Analysis of 464 non-test Go files across 18 packages revealed significant refactoring opportunities:
Key Finding: The codebase demonstrates good semantic organization at the function level but suffers from structural fragmentation that creates maintenance burden and cognitive overhead.
Analysis Scope
Files Analyzed: 464 Go source files (excluding tests)
Packages Analyzed: 18 top-level packages in
pkg/Focus Areas:
Primary Analysis Areas:
*_validation.gopattern)1. Package Structure Analysis
Package Distribution by Size
Critical Complexity: workflow Package
Statistics:
Issue: The workflow package is a "monster package" where semantic clusters exist in naming but not in structure, making navigation difficult and boundaries unclear.
2. Validation Files: 76+ Duplicate Patterns
Overview
Files: 27 files matching
*_validation.gopattern + 1 outlier (permissions_validator.go)Total Functions: 63 validation functions
Duplicate Patterns: 76+ instances across 7 pattern categories
High-Impact Duplicates
Pattern A: Empty String/Nil Checking (40+ instances)
Severity: HIGH
Files Affected: 25+ validation files
Pattern:
Examples:
agent_validation.go:61-if workflowData.AgentFile == "" { return nil }features_validation.go:37-if data == nil || data.Features == nil { return nil }sandbox_validation.go:84-if workflowData.SandboxConfig == nil { return nil }runtime_validation.go:98-if workflowData.Tools == nil { return nil }Recommendation: Extract to shared helper
Impact: Eliminate 40+ lines of repetitive code, establish consistent validation pattern
Pattern B: Map Type Assertion (30+ instances)
Severity: HIGH
Files Affected: 15+ validation files
Pattern:
Examples:
mcp_config_validation.go:86, 127, 132, 200(4 instances)runtime_validation.go:105dispatch_workflow_validation.go:89, 102, 117, 157, 167, 177(6 instances)compiler_filters_validation.go:52, 80safe_outputs_domains_validation.go(multiple)agent_validation.go:127Recommendation: Create assertion helpers