Skip to content

[refactor] Semantic function clustering: decompose large multi-cluster files (audit.go, import_field_extractor.go)Β #43890

Description

@github-actions

πŸ”§ Semantic Function Clustering Analysis

Analysis of repository: github/gh-aw β€” non-test Go sources under pkg/

Overview

Analyzed 1,011 non-test .go files. Function names were extracted across the tree, clustered by naming/purpose, and cross-file name collisions were verified against their implementations to distinguish real duplication from legitimate Go patterns.

Headline: the codebase is already well-factored. Shared utilities live in dedicated packages (stringutil, sliceutil, setutil, fileutil, jsonutil, timeutil, semverutil, ...), and every naming-based duplicate candidate turned out to be a legitimate pattern (see Verified non-findings). The only actionable refactoring signal is a small number of very large, multi-cluster files that mix several internal function groups and could be split by cluster.

Package Non-test files Note
pkg/workflow 431 Compiler / YAML generation
pkg/cli 339 Cobra commands
pkg/parser 43 Frontmatter / imports
pkg/console 29 Rendering
others ~169 util + linters

Key finding: large multi-cluster files (one-file-per-feature candidates)

These files are internally on-topic but large enough to contain distinct function clusters that would read better as separate files. Function names below are verbatim from source.

pkg/cli/audit.go β€” 1,257 lines, 63 functions

Four separable clusters live in one file:

  • Command setup / orchestration: NewAuditCommand, registerAuditCommandFlags, runAuditCommand, runAuditSingle, runAuditMulti, resolveAuditCommandArgs
  • Analysis launching: launchCoreAuditAnalyses, launchMetricsAnalysis, launchJobDetailsAnalysis, launchFirewallAuditAnalyses, launchSupplementalAuditAnalyses, collectAuditAnalysisResults
  • Rendering: renderAuditReport, renderAuditOutput, renderAuditGatewayMetrics, renderAuditUnifiedTimeline, renderAuditCompletion, renderAuditJobSummary
  • Job / step extraction: fetchAuditJobLog, extractAuditJobDetails, extractRequestedStepOutput, extractFirstFailingStepOutput, findFirstFailingStep

Likely outliers (workflow-metadata helpers, not audit-specific): fetchWorkflowRunMetadata, buildWorkflowRunMetadataArgs, classifyWorkflowRunMetadataError, resolveWorkflowRunDisplayName, resolveWorkflowDisplayName, extractWorkflowNameFromYAML.

Suggestion: split rendering into audit_render.go (peers audit_report_render.go, audit_diff_render.go already exist), job extraction into audit_job.go, and move the workflow-metadata helpers next to existing workflow-metadata code.

pkg/parser/import_field_extractor.go β€” 1,369 lines, 57 functions

Three clusters:

  • Field extraction (core): extractAllImportFields, extractEngineConfig, extractConfigFields, extractActivationFields, extractStepAndJobFields, appendJSONBuilderField, appendYAMLBuilderField, ...
  • Schema validation: validateGitHubAppJSON, validateWithImportSchema, validateObjectInput, validateImportInputType, applyImportSchemaDefaultsFromFrontmatter
  • Input substitution: substituteImportInputsInContent, buildImportInputReplaceFunc, resolveImportInputPath, resolveImportInputValue, computeImportRelPath

Suggestion: extract into import_validation.go and import_input_substitution.go, leaving the extractor focused on field extraction.

Other size outliers (verify before splitting)
File Lines Funcs Character
pkg/workflow/safe_outputs_config.go 1,254 8 Data-heavy (config structs) β€” not a clustering target
pkg/workflow/compiler_yaml_main_job.go 1,163 20 Large template emitters
pkg/workflow/frontmatter_extraction_yaml.go 1,179 16 YAML extraction
pkg/workflow/compiler_yaml.go 1,129 18 YAML generation
pkg/cli/logs_orchestrator.go 1,278 13 Log orchestration
pkg/workflow/compiler_activation_job_builder.go 1,110 43 Cohesive β€” all *Activation* step-builders; borderline (permissions sub-cluster buildActivation*Permissions + env sub-cluster buildActivation*Env could be extracted)
pkg/workflow/awf_helpers.go 1,054 24 Helper grab-bag β€” worth a cluster review
pkg/workflow/domains.go 1,061 β€” Mostly domain data

pkg/parser/remote_fetch.go (1,553 lines) is already tracked for splitting β€” see #43792 and #43834 β€” and is excluded here to avoid duplication.

Verified non-findings (transparency)

Naming-based duplicate detection produced candidates that were checked against source and are legitimate β€” no action needed:

  • SanitizeName in both pkg/workflow/strings.go and pkg/stringutil/sanitize.go β€” the workflow copy is a thin re-export (return stringutil.SanitizeName(...)) with a SanitizeOptions type alias. Intentional, already consolidated.
  • IsStdoutTerminal / IsStderrTerminal in tty.go + tty_wasm.go β€” build-tag variants (wasm), required.
  • RenderMCPConfig, GetSupportedEnvVarKeys, GetInstallationSteps, GetExecutionSteps, ... (Γ—9 each) β€” engine interface implementations (polymorphism), not duplicates.
  • Error / String / UnmarshalJSON / Unwrap β€” standard-library interface implementations.
  • contains, findRepoRoot collisions β€” all in _test.go files (excluded from scope).

Next actions

Analysis metadata

  • Non-test Go files analyzed: 1,011
  • Function clusters reviewed: naming-pattern + cross-file collision analysis
  • Real duplicates found: 0 (all candidates verified legitimate)
  • Outlier / god-file split candidates: 2 high-confidence (audit.go, import_field_extractor.go) + follow-ups
  • Method: function-signature extraction + Serena-configured Go workspace + source verification of every collision
  • Analysis date: 2026-07-07

Generated by πŸ”§ Semantic Function Refactoring Β· 256.6 AIC Β· βŒ– 15.4 AIC Β· ⊞ 9.2K Β· β—·

  • expires on Jul 8, 2026, 4:14 PM UTC-08:00

Activity

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

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions