[typist] π€ Typist β Go Type Consistency Analysis #46240
Closed
Replies: 1 comment
|
This discussion was automatically closed because it expired on 2026-07-18T12:10:58.032Z.
|
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.
Analysis of repository: github/gh-aw
Executive Summary
Good news first: this codebase is already in strong shape on type safety. Across ~290 non-test Go files and ~510 named type definitions in
pkg/, most shared shapes are already consolidated through base-type embedding (BaseMCPServerConfig,BaseSafeOutputConfig,BaseEngine,FirewallSummaryBase,TokenCoreMetrics), and the code consistently uses semantic named types (ActionMode,EngineName,GitHubMCPMode,WorkflowID,LineLength) instead of bare strings and ints. Empty interface is effectively unused as a real type β the code has standardized onany, and the vast majority ofanyusage is legitimatemap[string]anyfor arbitrary YAML/JSON frontmatter and template data.So this is not a the code is a mess report β it is a short, high-signal punch list. The genuine opportunities cluster in two places: (1) a handful of near-duplicate report DTOs in
pkg/cliwhere the logs pipeline and the audit pipeline independently grew parallel structs (for exampleJobStepandJobStepDataare defined byte-for-byte identically in the same package), and (2) a handful of mode/policy string constants that should become named string types to match the pattern the codebase already uses elsewhere. Fixing the top few removes real type-assertion churn and one literally-duplicated definition.Full Analysis Report
Duplicated Type Definitions
Summary Statistics
pkg/): ~290JobStep/JobStepData)_wasm.govariants, data-vs-display DTO projections, coincidentalPolicyRulename collisionCluster 1:
JobStep/JobStepDataβ exact duplicateKind: Exact Β· Occurrences: 2 Β· Impact: High (zero-risk)
Locations:
pkg/cli/logs_models.go:272Β·pkg/cli/audit_report.go:127Both declare three string fields β Name (json tag
name), Status (json tagstatus,omitempty), Conclusion (json tagconclusion,omitempty) β in the same packagecli.JobStepDatais byte-identical toJobStep.Recommendation: Delete
JobStepDataand useJobStepeverywhere, or addtype JobStepData = JobStepas a transitional alias. Effort: ~15 min Β· Benefit: single source of truth, no downside.Cluster 2:
JobInfo/JobDataβ near duplicateKind: Near Β· Occurrences: 2 Β· Impact: High
Locations:
pkg/cli/logs_models.go:262Β·pkg/cli/audit_report.go:118JobInfo(logs) has Name/Status/Conclusion strings, StartedAt/CompletedAttime.Time, Steps[]JobStep.JobData(audit) has Name/Status/Conclusion/Duration strings withconsole:display tags, Steps[]JobStepData. Same concept: a workflow job with steps; the only real difference is raw timestamps vs a precomputed Duration string plus render tags.Recommendation: Add the
console:tags (and a derived Duration or render-time formatting) toJobInfo, then dropJobData. Effort: 1β2 h.Cluster 3:
MCPToolUsageData/MCPToolUsageSummaryβ near duplicateKind: Near Β· Occurrences: 2 Β· Impact: Medium
Locations:
pkg/cli/audit_report.go:174Β·pkg/cli/logs_models.go:188Four shared fields (Summary, Servers, ToolCalls, FilteredEvents) are element-type identical;
MCPToolUsageDataadditionally has an optional GuardPolicySummary pointer.Recommendation: Consolidate to the superset (
MCPToolUsageData); leave GuardPolicySummary optional and nil on the aggregated path. Effort: 1β2 h.Cluster 4:
ToolUsageSummary/ToolUsageInfoβ near duplicateKind: Near Β· Occurrences: 2 Β· Impact: Medium
Locations:
pkg/cli/logs_report_tools.go:13Β·pkg/cli/audit_report.go:163Both are per-tool aggregate stat rows overlapping on Name, a calls count, MaxOutputSize, MaxDuration; each adds a couple of unique fields (Runs/TotalCalls vs MaxInputSize/OutputSample).
Recommendation: Merge into one
ToolUsagestat struct with the superset of fields andomitempty. Effort: 1β2 h.Cluster 5: GitHub Action / workflow input definition β semantic duplicate
Kind: Semantic Β· Occurrences: 3 Β· Impact: Medium
Locations:
pkg/types/input_definition.go:15(InputDefinition) Β·pkg/cli/generate_action_metadata_command.go:46(ActionInput) Β·pkg/actionpins/actionpins.go:31(ActionYAMLInput)All three model a GitHub Action/workflow input.
ActionYAMLInputis a strict subset ofActionInput(minus Name);InputDefinitionis the richest (Defaultany+ Type + Options) and lives in sharedpkg/types.Recommendation: Have
ActionYAMLInput/ActionInputshare a common {Description, Required, Default} base. A full merge withtypes.InputDefinitionis harder (Defaultanyvsstring), so treat as a base-embedding opportunity. Effort: 2β3 h.Cluster 6:
AuditComparisonIntDelta/AuditComparisonStringDeltaβ semantic duplicateKind: Semantic Β· Occurrences: 2 Β· Impact: Low (clean generics win)
Location:
pkg/cli/audit_comparison.go:45and:51. Both are {Before; After; Changed bool} parameterized only by value type (int vs string).Recommendation: Replace with a single generic Delta[T comparable] holding Before, After, and a Changed bool. Effort: ~1 h.
Confirmed intentional β reviewed, no action needed
PolicyRule(pkg/cli/firewall_policy.go:36vspkg/intent/policy.go:46) β same name, entirely different concepts (firewall ACL rule vs intent-governance policy). Coincidental collision.RepositoryFeatures,SpinnerWrapper,ProgressBardefined once for the normal build and once in_wasm.gostubs behind build tags. Correct platform separation.OverviewData/OverviewDisplay,PolicyAnalysis/PolicySummaryDisplay,ModelTokenUsage/ModelTokenUsageRow. Each*Display/*Rowis a deliberately narrowed,console:-tagged projection; merging would couple JSON schema to console output.Untyped Usages
Summary Statistics
anyanyoccurrences: ~4600, but overwhelmingly intentional (map[string]anyfrontmatter, template data, decoded-node coercion helpers)The headline is not 4600 problems. It is ~15 realistic conversions, concentrated in
pkg/workflow/tools_types.go,pkg/workflow/safe_outputs_config_types.go,pkg/workflow/safe_outputs_validation.go,pkg/workflow/mcp_renderer_types.go,pkg/cli/mcp_registry_types.go, andpkg/github/label_objective_mapping*.go.Category 1: Untyped mode/policy constants β named string types (highest value, lowest risk)
The codebase already establishes this exact pattern with
ActionMode,EngineName, andGitHubMCPMode.Example 1 β safe-outputs URLs policy Β·
pkg/workflow/safe_outputs_validation.go:13. Bare constsSafeOutputsURLsPolicyAllowedOnly=allowed-onlyandSafeOutputsURLsPolicyAllowedOrCodeRegion=allowed-or-code-region, validated in a switch againstSafeOutputsConfig.URLs(plain string). Suggest a namedSafeOutputsURLsPolicystring type with anIsValid()method and retype the field.Example 2 β multi-label logic Β·
pkg/github/label_objective_mapping_constants.go:136(fieldObjectiveMapping.MultiLabelLogic string). Constsmax/sum/first. Suggest a namedMultiLabelLogicstring type.Example 3 β MCP registry status / argument type Β·
pkg/cli/mcp_registry_types.go:107. Constsactive/inactiveandpositional/named. Suggest namedServerStatusandArgumentTypestring types (useArgumentTypeforArgument.Type).Examples 4 and 5 β MCP / Playwright transport modes Β·
pkg/workflow/tools_types.go:384(Playwrightmcp/cli) and:441(MCP serverstdio/http/remote/local). Suggest namedPlaywrightModeandMCPServerModestring types β same idiom as the neighboringGitHubMCPMode.Category 2:
anystruct fields with a known two-shape union β concrete typesReportFailureAsIssue anyΒ·pkg/workflow/safe_outputs_config_types.go:105β bool | templatable expression string |[]stringcategories (already parsed into sibling typed fields). Suggest a tagged type or reuse*TemplatableBool+ the typed category slices.GitHubReposScope anyΒ·pkg/workflow/tools_types.go:302(AllowedRepos, Repos) β a string (all/public) OR[]anyof repo patterns. Suggest a concrete struct with a Keyword string and Patterns []string, populated at parse time.PrivateToPublicFlows anyΒ·pkg/workflow/tools_types.go:375β the stringallowOR[]stringof MCP server IDs. Suggest a struct with an AllowAll bool and ExemptServers []string.Steps []anyΒ·pkg/workflow/safe_outputs_config_types.go:110β each element is a GitHub Actions step (map[string]any); sibling fields already use[]map[string]any. SuggestSteps []map[string]any.Category 3:
anyin function params / map values β existing concrete typesPlaywright renderer callback Β·
pkg/workflow/mcp_renderer_types.go:36β the RenderPlaywright callback takes playwrightTool asany. The concrete*PlaywrightToolConfigalready exists; pass it instead ofany.Guard-policy maps Β·
pkg/workflow/mcp_renderer_types.go(GuardPolicies map[string]any) andpkg/workflow/tools_types.go:448β compiler-constructed payload with fixed keys built from strongly-typedGitHubToolConfigguard fields. Suggest a sharedGuardPolicyConfigstruct.Reviewed and confirmed intentional any β do NOT change
pkg/workflow/dependabot.go:557,584βdependabotToAnySlice/dependabotToStringAnyMapare generic YAML-node coercion primitives.Samples []map[string]any,SecretMaskingConfig.Steps,WorkflowTrialResultmap fields (pkg/cli/trial_types.go) β genuine arbitrary JSON/YAML containers.anyoccurrences aremap[string]anyfrontmatter/decoding β idiomatic, out of scope.Refactoring Recommendations
Priority 1 β Critical, zero-risk: delete
JobStepData, useJobStep(or a transitional alias). ~15 min.Priority 2 β High: named string types for the mode/policy constants (
SafeOutputsURLsPolicy,MultiLabelLogic,ServerStatus/ArgumentType,PlaywrightMode,MCPServerMode) withIsValid(). Matches the existingActionMode/EngineName/GitHubMCPModeidiom; JSON/YAML decoding stays compatible. 3β4 h.Priority 3 β High/Medium: unify the
pkg/clireport DTOs (JobInfo/JobData,MCPToolUsage*,ToolUsage*) across the logs and audit pipelines. 4β6 h.Priority 4 β Medium: replace known-shape
anyfields with concrete types (ReportFailureAsIssue,GitHubReposScope,PrivateToPublicFlows,Steps []any,GuardPolicies,RenderPlaywright). 4β6 h.Priority 5 β Low: a generic Delta[T] for the audit deltas; a shared base for
ActionInput/ActionYAMLInput. 2β3 h.Implementation Checklist
JobStepData; point everything atJobStepIsValid())JobInfo/JobData,MCPToolUsage*,ToolUsage*across logs+auditanyfields with concrete/tagged typesAnalysis Metadata
pkg/): ~290 of 1102References: Β§29577956282
All reactions