[typist] π€ Typist β Go Type Consistency Analysis #47781
Closed
Replies: 1 comment
|
This discussion was automatically closed because it expired on 2026-07-25T12:18:10.320Z.
|
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.
π€ Typist - Go Type Consistency Analysis
Analysis of repository: github/gh-aw
Executive Summary
This codebase is remarkably disciplined about typing for its size. I analyzed 1,140 non-test
.gofiles underpkg/(~1,095 type definitions, ~730constsites) and found zero accidental exact-name type collisions in production code. The team already leans on named string types (EngineName,FeatureFlag,PermissionScope,PermissionLevel,ActionMode,AttributionStatus) and single-source re-export aliases (type X = pkg.X).So this is less "a mess" and more "a handful of clean, high-leverage tidy-ups." Standouts: a byte-identical experiment state struct defined twice in the same
clipackage (a ~15-min fix), a parallel models.dev catalog parser inpkg/clithat re-declares structs its own package already imports frompkg/modelsdev, and a three-valueLLMProviderenum threaded through ~8 functions as a barestringthat drives secret selection and gateway routing. Almost all ~4,000anyusages are idiomatic (parsed Actions YAML, JSON-Schema walking,go/analysissignatures), so I filtered aggressively and surface only the handful worth touching.Full Analysis Report
Duplicated Type Definitions
Stats: ~1,095 types analyzed Β· 5 real actionable clusters (1 exact, 4 near) Β· build-tag
*_wasm.gopairs and lintertestdatafixtures excluded as intentional.Cluster 1 β
ExperimentStatevsexperimentStateJSONΒ· Exact duplicate β Top pickpkg/cli/experiments_command.go:35βExperimentState(+ExperimentRunRecordat:41)pkg/cli/audit_report_experiments.go:35βexperimentStateJSON(+experimentRunRecordat:42)Both are byte-identical (
Counts map[string]map[string]int;Runs []...RunRecord), both in packagecli.experimentStateJSONis used in exactly one place (audit_report_experiments.go:92). Fix: delete the unexported pair, reuse the exported types at that single site. ~15 min.Cluster 2 β models.dev catalog parse structs Β· Near duplicate
pkg/cli/model_costs.go:20βmodelsCatalogData/modelsCatalogProvider/modelCostEntry(Costmap[string]string)pkg/modelsdev/catalog.go:32βrawCatalog/rawProvider/rawModel(Costmap[string]json.RawMessage)Same 3-level
CatalogβProviderβModel{Cost}JSON shape.model_costs.go:12already importspkg/modelsdevyet re-parses the catalog with its own structs. Fix: consumepkg/modelsdevβs types; unify theCostleaf. ~1-2 h.Cluster 3 β Firewall / domain aggregation bases Β· Near duplicate (mid-refactor)
pkg/cli/logs_report_firewall.go:17βFirewallSummaryBasepkg/cli/domain_buckets.go:41βAnalysisBase(embedsDomainBucketsat:13)pkg/cli/access_log.go:44βdomainAnalysisWire(legacyallowed_count/blocked_countjson tags)All hold
{TotalRequests, Allowed*, Blocked* int, AllowedDomains, BlockedDomains []string}. Fix: makeFirewallSummaryBasereuseAnalysisBase; keepdomainAnalysisWireonly as aMarshalJSONshim. ~1-2 h.Cluster 4 β
rateLimitResponsevsorgRateLimitResponseΒ· Near duplicatepkg/cli/logs_rate_limit.go:39andpkg/cli/update_org.go:48both wrapResources.Core rateLimitResource; the org variant only addsSearch. Fix: one struct with bothCoreandSearch. ~30 min. (Low.)Not duplication (single source of truth): re-export aliases
LogMetrics,ToolCallInfo,SanitizeOptions,InputDefinition,actionpins.*.Excluded as intentional (do NOT refactor)
!js && !wasmvsjs || wasm):RepositoryFeatures,SpinnerWrapper,ProgressBar(each native.go/_wasm.go).testdata/src/*packages:Worker,fakeOS,myString/myBytes.Untyped Usages
Stats:
interface{}= 18 (nearly all linter testdata/comments) Β·any~4,051 (map values 2,406 Β· slices 436 Β· params 241 Β· returns 134 Β· fields 35) Β· ~9 actionable Β· 8 untyped enum groups Β· 2 ambiguous numeric.Struct fields with a knowable type:
pkg/cli/logs_models.go:323-324βRunID any/RunNumber anyβint64/int(orjson.Number). Self-producedaw_info.jsonfields; removes downstream type switches. (Medium)pkg/console/console_types.go:50βValue any(always*string/*bool) β makeFormFieldgeneric (FormField[T any]withValue *T). (Medium)Slice elements that are always objects:
pkg/workflow/frontmatter_types.go:324,359-362βPreSteps/Steps/PreAgentSteps/PostSteps/Skills []anyβ[]map[string]any(steps are always mappings; drops per-element assertions). (Medium)Return types with a known root shape:
pkg/parser/schema_compiler.go:101(+ fields:57,:61) βgetParsedSchemaDoc(...) (any, error)β(map[string]any, error); a schema root is always an object. (Medium)Lower-impact any opportunities (optional)
pkg/cli/mcp_tools_privileged.go:299-300βRunID any/RunIDOrURL anyβjson.Number+ typed URL string.pkg/parser/remote_client.go:47βfetchRemoteFileContent(..., fileContent any)(one caller) β generic or concrete struct.pkg/workflow/pi_logs.go:29βParameters anyβmap[string]any.pkg/workflow/mcp_scripts_parser.go:60βDefault any(mirrorstypes/input_definition.go:18) β scalar accessor.pkg/parser/schema_suggestions.go:267,380-411β give leafgenerate*Examplehelpers concrete returns; keep composed rootany.Untyped string-enum constant groups:
LLMProviderΒ· High β βpkg/workflow/llm_provider.go:13:Drives
normalizeLLMProvider,resolveEngineLLMProvider,llmProviderProfileFor,llmProviderSecretNames/Expression, gateway/docs URL helpers, andEngineConfig.LLMProvider. Provider selection controls secret resolution and gateway routing β best safety-per-line in the report.MCP registry enums Β· Medium (exported) β
pkg/cli/mcp_registry_types.go:107:StatusActive/Inactiveβtype ServerStatus string;ArgumentTypePositional/Namedβtype ArgumentType string.More enum groups (medium/low)
pkg/workflow/safe_outputs_validation.go:13βSafeOutputsURLsPolicy(allowed-only/allowed-or-code-region); typeconfig.URLstoo. (medium)pkg/github/label_objective_mapping_constants.go:137βMultiLabelLogic(max/sum/first). (medium)pkg/cli/env_command.go:25βDefaultsScope(repo/org/ent). (medium)pkg/workflow/run_phase.go:3βRunPhase(agent/detection/evals). (low)pkg/cli/outcomes_history.go:23βHistorySource(issues/prs/all). (low)Ambiguous numeric constants:
pkg/cli/gateway_logs_types.go:61β guard-policy JSON-RPC codes-32001..-32006as bareintβtype GuardPolicyErrorCode int(+ aString()). (medium)pkg/constants/constants.go:126-135β gateway ports; already groupedint, aNetworkPorttype is marginal. (low)Prioritized Recommendations
experimentStateJSON/experimentRunRecord, reuse exported types (~15 min); (2) addtype LLMProvider stringand thread through helpers +EngineConfig.LLMProvider(~1-2 h, best payoff).pkg/modelsdevcatalog types inmodel_costs.go; (4) finish firewall/domain-buckets base consolidation; (5) merge rate-limit responses.RunID/RunNumberβint64/int; (7) step slices β[]map[string]any; (8)getParsedSchemaDocβmap[string]any.ServerStatus,ArgumentType,SafeOutputsURLsPolicy,MultiLabelLogic,DefaultsScope,GuardPolicyErrorCode.Run
go build ./...+ the full test suite after each change.Metadata: files scanned 1,140 Β· type defs ~1,095 Β· real duplicate clusters 5 Β·
any/interface{}~4,069 (~95%+ idiomatic; 9 actionable) Β·constsites ~730 (8 enum groups, 2 numeric) Β· method: Serena semantic analysis + pattern matching, verified against source Β· date 2026-07-24.All reactions