Skip to content

[refactor] Semantic function clustering: consolidate duplicate compileSchema; codebase otherwise well-organized #42587

Description

@github-actions

🔧 Semantic Function Clustering Analysis

Analysis of github/gh-aw — non-test .go files under pkg/ (986 files). Method: cross-package function-name clustering + Serena/gopls-assisted symbol inspection.

Overview

The codebase is already well-organized. It follows a strict one-feature-per-file convention (codemod_*.go, compile_*.go, logs_*.go, audit_*.go, gateway_logs_*.go), a dedicated stringutil package for shared string helpers, and consistent *_wasm.go build-tag splits. A full duplicate sweep across all top-level functions surfaced only one genuine cross-package near-duplicate plus a couple of low-priority indirection cleanups. No misplaced-function (outlier) issues of note were found.

Most apparent name collisions were false positives and are called out below so future runs don't re-flag them.

Key finding — duplicate compileSchema boilerplate

The JSON-schema compile boilerplate (NewCompiler → AddResource → Compile) is implemented twice, unexported, in two packages:

  • pkg/parser/schema_compiler.go:121func compileSchema(schemaJSON, schemaURL string) (*jsonschema.Schema, error)
  • pkg/workflow/schema_utils.go:14func compileSchema(schemaJSON, schemaURL string) (*jsonschema.Schema, error)

The bodies are functionally identical (differ only in log lines and error-message wording). workflow already imports parser (one-directional; parser does not import workflow), so consolidation is safe.

Recommendation: export the parser implementation (e.g. parser.CompileSchema) — or extract a small shared schemautil package — and have pkg/workflow/schema_utils.go delegate to it. Callers of the workflow copy: samples_validation.go:82, awf_config.go:94, schema_validation.go:64.

Impact: removes one duplicated implementation; low effort (~30 min), no behavior change.

Low-priority: delegating wrappers that add indirection

These are already correct (they forward to stringutil) but add a layer that callers could skip. Keep if the extra logging / API stability is intentional:

  • pkg/parser/schema_suggestions.go:231 FindClosestMatches and :241 LevenshteinDistance → forward to stringutil.*
  • pkg/workflow/strings.go:97 SanitizeName → forwards to stringutil.SanitizeName

Optional cleanup: point call sites directly at stringutil and drop the wrappers, unless the local Printf logging is desired.

False positives (NOT duplicates — do not refactor)
  • Build-tag pairs — same signature in foo.go (//go:build !js && !wasm) and foo_wasm.go (//go:build js || wasm). Legitimate platform variants: all pkg/console/* Format*/Render*/Print*/Spinner/Progress/ConfirmAction/isTTY; pkg/workflow/github_cli*.go ExecGH*/RunGH*; git_helpers*.go RunGitCombined/findGitRoot; docker_validation*.go isDockerDaemonRunning; pkg/parser/remote_fetch*.go ResolveIncludePath/IsWorkflowSpec/isWorkflowSpec; pkg/parser/github*.go GetGitHubToken.
  • Interface implementations across engine/type variantsRenderMCPConfig, GetSupportedEnvVarKeys, GetInstallationSteps, GetExecutionSteps, String, Error, UnmarshalJSON, IsValid, etc. (9× each). Expected polymorphism, not duplication.
  • Cobra command handlers — 39× run, one per command file. Idiomatic.
  • Linter testdata fixtures — e.g. pkg/linters/errormessage/testdata/.../NewValidationError. Intentional test inputs.
  • Same-name / different-purposeextractToolsFromFrontmatter exists in parser ((string, error)) and workflow (map[string]any); different contracts, name collision only.

Next actions

  • Consolidate the two compileSchema implementations (Priority 1, low effort)
  • (optional) Remove stringutil delegating wrappers in parser/workflow if the extra logging isn't needed
  • No action required for the false-positive categories above

Analysis metadata

Generated by 🔧 Semantic Function Refactoring · 192.7 AIC · ⌖ 7.77 AIC · ⊞ 9.2K ·

  • expires on Jul 2, 2026, 4:12 PM UTC-08:00

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions