π§ Semantic Function Clustering Analysis
Analysis of repository: github/gh-aw β non-test .go files under pkg/
Overview
A semantic clustering + duplicate sweep over 940 non-test Go files (4,405 top-level funcs, 1,233 methods) found the codebase already well-factored: nearly every same-name cross-package match is either an intentional delegating shim or a legitimate build-tag variant. One genuine duplicate stands out and is worth consolidating.
| Metric |
Value |
| Non-test Go files analyzed |
940 |
| Largest packages |
workflow (408), cli (322), linters (81), parser (44) |
| Genuine cross-package duplicate found |
1 (hasStringKey) |
| False positives correctly excluded |
shims + *_wasm.go build variants |
Key finding: hasStringKey duplicated across 6 packages
The exact same 4-line helper is defined in 6 separate seenmapbool_helpers.go files (function bodies byte-identical; only the package line differs):
func hasStringKey(set map[string]struct{}, key string) bool {
_, ok := set[key]
return ok
}
| Package |
File |
constants |
pkg/constants/seenmapbool_helpers.go |
linters/ssljson |
pkg/linters/ssljson/seenmapbool_helpers.go |
agentdrain |
pkg/agentdrain/seenmapbool_helpers.go |
workflow |
pkg/workflow/seenmapbool_helpers.go |
parser |
pkg/parser/seenmapbool_helpers.go |
cli |
pkg/cli/seenmapbool_helpers.go |
Scale: 196 call sites across these packages (workflow ~90, cli ~50, parser ~12, plus constants/agentdrain/ssljson). The filename and the identical body indicate these were emitted by the map[string]bool β map[string]struct{} migration codemod rather than hand-written.
Recommendation
Introduce a tiny dependency-free leaf util (matching the existing pkg/sliceutil / pkg/typeutil / pkg/stringutil convention) with a generic signature, then delete the 6 copies:
// pkg/setutil/setutil.go (or add to pkg/typeutil)
package setutil
// Contains reports whether key is present in a set built as map[K]struct{}.
func Contains[K comparable](set map[K]struct{}, key K) bool {
_, ok := set[key]
return ok
}
Then replace hasStringKey(set, k) β setutil.Contains(set, k) across the 196 sites (mechanical, e.g. gofmt -r or codemod). pkg/constants is low-level, but a brand-new leaf package with zero imports introduces no cycle. The generic form also covers any future non-string sets for free.
Also fix the source: update the codemod that emits seenmapbool_helpers.go so it references the shared helper instead of generating a per-package copy β otherwise the duplicates regrow on the next migration run.
Why the other same-name matches are not duplicates (verified)
SanitizeName / SanitizeOptions β pkg/workflow/strings.go is already a type-alias + delegating shim to pkg/stringutil (func SanitizeName(...) { return stringutil.SanitizeName(...) }). β
Already centralized.
LevenshteinDistance β pkg/parser/schema_suggestions.go is a one-line wrapper returning stringutil.LevenshteinDistance(a, b). β
Already centralized.
findGitRoot, RunGH, RunGHContext, RunGHCombined, getDefaultGHHost, IsWorkflowSpec/isWorkflowSpec β these pair foo.go with foo_wasm.go; the second copy is a build-tag-gated WASM stub, not a duplicate. β
Excluded.
extractToolsFromFrontmatter β exists in workflow (returns map[string]any) and parser (returns (string, error)): same name, genuinely different purpose/signature in different packages. Package namespacing, not duplication. β
Acceptable.
run (31Γ), init (13Γ) β standard Cobra command + package-init patterns. β
Idiomatic.
Next actions
Detection method: top-level func-name clustering across all non-test .go files + body-identity (md5) verification + manual confirmation of each candidate. Analysis date: 2026-06-21.
References: Β§27887885991
Generated by π§ Semantic Function Refactoring Β· 163.9 AIC Β· β 14.9 AIC Β· β 9.1K Β· β·
π§ Semantic Function Clustering Analysis
Analysis of repository: github/gh-aw β non-test
.gofiles underpkg/Overview
A semantic clustering + duplicate sweep over 940 non-test Go files (4,405 top-level funcs, 1,233 methods) found the codebase already well-factored: nearly every same-name cross-package match is either an intentional delegating shim or a legitimate build-tag variant. One genuine duplicate stands out and is worth consolidating.
workflow(408),cli(322),linters(81),parser(44)hasStringKey)*_wasm.gobuild variantsKey finding:
hasStringKeyduplicated across 6 packagesThe exact same 4-line helper is defined in 6 separate
seenmapbool_helpers.gofiles (function bodies byte-identical; only thepackageline differs):constantspkg/constants/seenmapbool_helpers.golinters/ssljsonpkg/linters/ssljson/seenmapbool_helpers.goagentdrainpkg/agentdrain/seenmapbool_helpers.goworkflowpkg/workflow/seenmapbool_helpers.goparserpkg/parser/seenmapbool_helpers.goclipkg/cli/seenmapbool_helpers.goScale: 196 call sites across these packages (workflow ~90, cli ~50, parser ~12, plus constants/agentdrain/ssljson). The filename and the identical body indicate these were emitted by the
map[string]boolβmap[string]struct{}migration codemod rather than hand-written.Recommendation
Introduce a tiny dependency-free leaf util (matching the existing
pkg/sliceutil/pkg/typeutil/pkg/stringutilconvention) with a generic signature, then delete the 6 copies:Then replace
hasStringKey(set, k)βsetutil.Contains(set, k)across the 196 sites (mechanical, e.g.gofmt -ror codemod).pkg/constantsis low-level, but a brand-new leaf package with zero imports introduces no cycle. The generic form also covers any future non-string sets for free.Also fix the source: update the codemod that emits
seenmapbool_helpers.goso it references the shared helper instead of generating a per-package copy β otherwise the duplicates regrow on the next migration run.Why the other same-name matches are not duplicates (verified)
SanitizeName/SanitizeOptionsβpkg/workflow/strings.gois already a type-alias + delegating shim topkg/stringutil(func SanitizeName(...) { return stringutil.SanitizeName(...) }). β Already centralized.LevenshteinDistanceβpkg/parser/schema_suggestions.gois a one-line wrapper returningstringutil.LevenshteinDistance(a, b). β Already centralized.findGitRoot,RunGH,RunGHContext,RunGHCombined,getDefaultGHHost,IsWorkflowSpec/isWorkflowSpecβ these pairfoo.gowithfoo_wasm.go; the second copy is a build-tag-gated WASM stub, not a duplicate. β Excluded.extractToolsFromFrontmatterβ exists inworkflow(returnsmap[string]any) andparser(returns(string, error)): same name, genuinely different purpose/signature in different packages. Package namespacing, not duplication. β Acceptable.run(31Γ),init(13Γ) β standard Cobra command + package-init patterns. β Idiomatic.Next actions
pkg/setutil(ortypeutil) with genericContains[K comparable]hasStringKeycall sites; delete the 6seenmapbool_helpers.gocopiesgo build ./... && go test ./...to confirm no behavior changeDetection method: top-level func-name clustering across all non-test
.gofiles + body-identity (md5) verification + manual confirmation of each candidate. Analysis date: 2026-06-21.References: Β§27887885991