π§ 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 Β· β·
π§ Semantic Function Clustering Analysis
Analysis of repository:
github/gh-awβ non-test Go sources underpkg/Overview
Analyzed 1,011 non-test
.gofiles. 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.pkg/workflowpkg/clipkg/parserpkg/consoleKey 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 functionsFour separable clusters live in one file:
NewAuditCommand,registerAuditCommandFlags,runAuditCommand,runAuditSingle,runAuditMulti,resolveAuditCommandArgslaunchCoreAuditAnalyses,launchMetricsAnalysis,launchJobDetailsAnalysis,launchFirewallAuditAnalyses,launchSupplementalAuditAnalyses,collectAuditAnalysisResultsrenderAuditReport,renderAuditOutput,renderAuditGatewayMetrics,renderAuditUnifiedTimeline,renderAuditCompletion,renderAuditJobSummaryfetchAuditJobLog,extractAuditJobDetails,extractRequestedStepOutput,extractFirstFailingStepOutput,findFirstFailingStepLikely outliers (workflow-metadata helpers, not audit-specific):
fetchWorkflowRunMetadata,buildWorkflowRunMetadataArgs,classifyWorkflowRunMetadataError,resolveWorkflowRunDisplayName,resolveWorkflowDisplayName,extractWorkflowNameFromYAML.Suggestion: split rendering into
audit_render.go(peersaudit_report_render.go,audit_diff_render.goalready exist), job extraction intoaudit_job.go, and move the workflow-metadata helpers next to existing workflow-metadata code.pkg/parser/import_field_extractor.goβ 1,369 lines, 57 functionsThree clusters:
extractAllImportFields,extractEngineConfig,extractConfigFields,extractActivationFields,extractStepAndJobFields,appendJSONBuilderField,appendYAMLBuilderField, ...validateGitHubAppJSON,validateWithImportSchema,validateObjectInput,validateImportInputType,applyImportSchemaDefaultsFromFrontmattersubstituteImportInputsInContent,buildImportInputReplaceFunc,resolveImportInputPath,resolveImportInputValue,computeImportRelPathSuggestion: extract into
import_validation.goandimport_input_substitution.go, leaving the extractor focused on field extraction.Other size outliers (verify before splitting)
pkg/workflow/safe_outputs_config.gopkg/workflow/compiler_yaml_main_job.gopkg/workflow/frontmatter_extraction_yaml.gopkg/workflow/compiler_yaml.gopkg/cli/logs_orchestrator.gopkg/workflow/compiler_activation_job_builder.go*Activation*step-builders; borderline (permissions sub-clusterbuildActivation*Permissions+ env sub-clusterbuildActivation*Envcould be extracted)pkg/workflow/awf_helpers.gopkg/workflow/domains.gopkg/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:
SanitizeNamein bothpkg/workflow/strings.goandpkg/stringutil/sanitize.goβ the workflow copy is a thin re-export (return stringutil.SanitizeName(...)) with aSanitizeOptionstype alias. Intentional, already consolidated.IsStdoutTerminal/IsStderrTerminalintty.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,findRepoRootcollisions β all in_test.gofiles (excluded from scope).Next actions
pkg/cli/audit.goandpkg/parser/import_field_extractor.goby the clusters above; relocate the workflow-metadata outliers out ofaudit.go. Pure function moves within a package β no signature or behavior change; existing tests should pass unchanged.pkg/workflow/awf_helpers.go(24-function grab-bag) for cluster extraction; consider extracting the permissions/env sub-clusters fromcompiler_activation_job_builder.go.safe_outputs_config.go/domains.go(data-heavy, not function clusters);remote_fetch.go(already tracked in [file-diet] Refactorpkg/parser/remote_fetch.go(1553 lines) into focused modulesΒ #43792 / refactor(parser): split remote_fetch.go (1553 lines) into focused modulesΒ #43834).Analysis metadata
audit.go,import_field_extractor.go) + follow-ups