Skip to content

[WIP] Refactor semantic function clustering in codebase#6567

Closed
Copilot wants to merge 1 commit into
mainfrom
copilot/refactor-function-clustering-analysis
Closed

[WIP] Refactor semantic function clustering in codebase#6567
Copilot wants to merge 1 commit into
mainfrom
copilot/refactor-function-clustering-analysis

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 15, 2025

Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.

Original prompt

This section details on the original issue you should resolve

<issue_title>[refactor] Semantic Function Clustering Analysis - Refactoring Opportunities</issue_title>
<issue_description>## Executive Summary

Comprehensive semantic analysis of the Go codebase revealed 1,790 function and method declarations across 299 non-test files in 12 packages. The analysis identified critical refactoring opportunities through function clustering, naming pattern analysis, and duplicate detection.

Key Findings

  • 🔴 111 config functions scattered across 30+ files without centralization
  • 🔴 72 validation functions lacking consistent interface or framework
  • 🔴 131 builder functions without standardized pattern implementation
  • 🔴 84 rendering functions distributed across multiple engine files
  • ⚠️ Duplicate parsing functions found in config_helpers.go and safe_output_builder.go
  • ⚠️ 6 files with >30 functions requiring splitting
  • Average 6.0 functions per file - generally healthy organization
Full Analysis Report

Analysis Scope

Files Analyzed: 299 non-test Go files (excluding *_test.go)
Total Declarations: 1,790 (1,256 functions + 534 methods)
Analysis Date: 2025-12-15

Package Distribution

Package Files Functions Methods Total Avg/File
workflow 164 594 455 1,049 6.4
cli 100 458 54 512 5.1
parser 14 128 13 141 10.1
console 5 37 5 42 8.4
campaign 7 20 0 20 2.9
logger 3 10 7 17 5.7
Other (6 packages) 6 9 0 9 1.5

Critical Findings

1. Config Management Crisis (111 *Config Functions)

Issue: Configuration parsing functions are scattered across 30+ files without centralization or consistent interface.

Distribution:

  • workflow: 97 config functions (scattered)
  • cli: 12 config functions
  • parser: 1 config function
  • console: 1 config function

Examples:

pkg/workflow/config_helpers.go:
  - parseLabelsFromConfig()
  - parseTitlePrefixFromConfig()
  - parseTargetRepoFromConfig()
  - parseParticipantsFromConfig()
  - parseAllowedReposFromConfig()
  - parseAllowedLabelsFromConfig()
  - parseExpiresFromConfig()
  - extractStringFromMap()

pkg/workflow/safe_output_builder.go:
  - parseRequiredLabelsFromConfig()
  - parseRequiredTitlePrefixFromConfig()
  - ParseStringFromConfig()
  - ParseStringArrayFromConfig()

Duplicate Detection: The functions in safe_output_builder.go duplicate functionality from config_helpers.go:

  • ParseStringFromConfig() vs extractStringFromMap() - ~95% duplicate
  • parseRequiredLabelsFromConfig() vs parseLabelsFromConfig() - ~90% similar

Other scattered config functions:

  • parseCommentsConfig(), parseAddLabelsConfig(), parseAddReviewerConfig()
  • parseAssignMilestoneConfig(), parseAssignToAgentConfig(), parseAssignToUserConfig()
  • extractCacheMemoryConfig(), extractCacheMemoryConfigFromMap()
  • RenderMCPConfig(), renderClaudeMCPConfig()
  • ... 87 more across workflow package

Recommendation:

  1. Consolidate all config parsing into pkg/workflow/config_parsing.go
  2. Create interface:
    type ConfigParser interface {
        ParseConfig(raw interface{}) (Config, error)
    }
  3. Merge duplicates: Use extractStringFromMap() everywhere instead of multiple implementations
  4. Standardize naming: All config parsing should use consistent parse*FromConfig() pattern

Estimated Impact:

  • 20-30% reduction in config parsing code
  • Single source of truth for config logic
  • Easier to add new config types
  • Simplified testing

2. Validation Fragmentation (72 Functions Across 4 Packages)

Issue: Validation functions lack consistent interface, making testing difficult and code hard to maintain.

Distribution:

  • workflow: 51 validation functions (scattered across 10 files)
  • cli: 7 validation functions
  • parser: 10 validation functions (well-organized in schema.go)
  • campaign: 4 validation functions

Examples:

pkg/workflow/:
  - validateAgentFile() - agent_validation.go:31
  - validateHTTPTransportSupport() - bundler_validation.go:45
  - validateStrictPermissions() - permissions_validator.go:67
  - ValidateActionSHAsInLockFile() - action_sha_checker.go:12

pkg/parser/schema.go (well-organized):
  - ValidateMainWorkflowFrontmatterWithSchema() - schema.go:65
  - ValidateIncludedFileFrontmatterWithSchema() - schema.go:107
  - ValidateMCPConfigWithSchema() - schema.go:138
  - validateWithSchema() - schema.go:266

Observation: Parser package has excellent validation organization - should be used as model.

Recommendation:

  1. Create validation framework in pkg/workflow/validation_framework.go:

...


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] Semantic Function Clustering Analysis - Refactoring Opportunities

3 participants