Typist - Go Type Consistency Analysis #22655
Closed
Replies: 1 comment
-
|
This discussion has been marked as outdated by Typist - Go Type Analysis. A newer discussion is available at Discussion #22871. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This report analyzes all 607 non-test Go source files in
pkg/for duplicated type definitions and untyped usages. The codebase demonstrates clear architectural awareness of typing concerns — a sharedpkg/typesbase package exists andFrontmatterConfigalready comments on specificmap[string]anyfields explaining their necessity. The primary opportunities are consistency improvements (untyped constants in groups where peers are already typed) and targeted reduction ofmap[string]anyin areas where structure is known.The 4 duplicate struct name pairs are all intentional build-tag separated implementations (wasm vs native), not true duplicates. The largest refactoring surface is in
map[string]anyusage across 249 files, most of which reflects genuinely dynamic YAML parsing — but a notable subset can be improved.Summary
map[string]anyoccurrences[]anyoccurrencesFull Analysis Report
Duplicated Type Definitions
Cluster 1:
MCPServerConfig— Intentional Domain Split ✅Type: Near-duplicate with shared base
Occurrences: 2
Verdict: Architecture is correct — not a refactoring target
pkg/parser/mcp.go:35Name,Registry,ProxyArgs,Allowedpkg/workflow/tools_types.go:489Mode,Toolsets,GuardPolicies,CustomFieldsBoth embed
types.BaseMCPServerConfigfrompkg/types, which is already the correct pattern for shared fields. No action needed.Cluster 2:
ProgressBar— Platform Build-Tag Split ✅Type: Wasm vs native implementation
Verdict: Intentional, not a refactoring target
pkg/console/progress.go:31//go:build !js && !wasmpkg/console/progress_wasm.go:7//go:build js || wasmSame pattern applies to
SpinnerWrapperinpkg/console/spinner.goandpkg/console/spinner_wasm.go.Cluster 3:⚠️
RepositoryFeatures— Identical Struct in Build-Tag SplitType: Identical struct in two files
Occurrences: 2
pkg/workflow/repository_features_validation.go:57pkg/workflow/repository_features_validation_wasm.go:5//go:build js || wasmUnlike
ProgressBar/SpinnerWrapper, the struct body is 100% identical between wasm and native. The difference is only thevalidateRepositoryFeaturesfunction — wasm returnsnilimmediately.Recommendation: Extract the
RepositoryFeaturesstruct to a shared file without build constraints, keeping onlyvalidateRepositoryFeaturesin the build-tag-separated files.Untyped Usages
Category 1: Output Name Constants — Missing Semantic Type (High Value)
The
pkg/constants/constants.gofile defines strongly typed constants forStepID,JobName,WorkflowID,EngineName,MCPServerID, etc. However, 11 output name constants are bare untyped strings:Suggested fix (following the existing pattern in the same file):
StepID,JobNamepattern; compile-time prevention of misuseCategory 2: Container/Image Constants — Inconsistent Typing
Version constants consistently use the
Versiontype, but container image constants are untyped despite being the same "registry path" concept:A
ContainerImage stringtype would make the distinction between container registry references and other strings explicit.Category 3: Numeric Untyped Constants
DefaultMCPGatewayPort = 80is defined inside a const block without an explicit type.These are lower priority since Go's type system infers numeric types correctly for arithmetic, but explicit types would add semantic clarity.
Category 4:
map[string]anyUsage — Large Surface, Largely Justified1,438 occurrences across 249 files. The codebase already documents why many of these must remain dynamic:
The existing
FrontmatterConfigstruct is itself a migration from rawmap[string]any— several fields already have typed alternatives (Tools *ToolsConfig,SafeOutputs *SafeOutputsConfig,RuntimesTyped *RuntimesConfig).Most actionable opportunities (not yet typed):
GuardPoliciespkg/workflow/mcp_renderer_types.go:21,87,114map[string]anyGuardPoliciesConfigtypeInputSchemapkg/workflow/mcp_scripts_generator.go:20map[string]anyExtraFieldspkg/workflow/runtime_definitions.go:27map[string]anywithfields from user's setup step" — could usemap[string]stringDevcontainerFeatures(pkg/cli/devcontainer.go:39) already demonstrates the pattern:MapToolConfig(pkg/workflow/mcp_config_types.go:66) is another good example:These named-alias patterns reduce the raw
map[string]anysurface while maintaining flexibility.GitHubReposScope(pkg/workflow/tools_types.go:285) shows a typed alias forany:Refactoring Recommendations
Priority 1: Add
OutputNameType to Constants (High impact, low effort)pkg/constants/constants.go:746–756type OutputName stringfollowing the existingStepID/JobNamepattern; retype the 11 output name constantsOutputName stringtype withString()methodOutputName(search for each constant usage)Priority 2: Extract
RepositoryFeaturesfrom Build-Tag Files (Low effort)pkg/workflow/repository_features_validation.goand_wasm.gorepository_features_types.gowithout build constraintspkg/workflow/repository_features_types.gowith the structPriority 3: Type Container/Image Constants (Medium effort)
pkg/constants/constants.goContainerImage stringtype for the 9 container/image string constantsContainerImage stringtype following existing patternsImplementation Checklist
OutputNametype and retype 11 output-name constants inpkg/constants/constants.goRepositoryFeaturesstruct to a build-tag-free shared fileContainerImagetype for container/image reference constantsGuardPoliciesConfigstruct to replacemap[string]anyon the 3 renderer config structsFrontmatterConfig map[string]anyfields toward typed structs (ongoing)Analysis Metadata
pkg/)map[string]anyOccurrences: 1,438 in 249 files (majority justified by YAML dynamism)References:
Beta Was this translation helpful? Give feedback.
All reactions