You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Analysis of repository: github/gh-aw-mcpg β Β§29703870629
Executive Summary
Analysis of 158 Go source files (excluding test files) across the internal/ directory cataloged 956 functions. The codebase is overall well-organized with clear package boundaries, but four categories of refactoring opportunities were identified: outlier functions that don't belong in their current files, near-duplicate extraction patterns, redundant filesystem-write scaffolding, and scattered typed-argument-decoding helpers.
No severe disorganization was found β findings are moderate-impact improvements targeting code centralization and cleaner separation of concerns.
Identified Issues
1. Outlier Functions (Functions in Wrong Files)
GenerateRandomAgentID in internal/auth/header.go
Function: GenerateRandomAgentID() (string, error)
Issue: All other functions in this file parse or validate auth headers. Random ID generation is an entropy/credential utility concern.
Recommendation: Move to internal/util/random.go (already has random utilities) or a dedicated internal/auth/id.go.
parseServerIDFromToolName in internal/middleware/jqschema.go
Issue: The file handles jq filtering, schema processing, and payload persistence. Tool-name parsing is a generic naming helper unrelated to these concerns.
Recommendation: Extract to a shared tool-name utility near internal/server/ tool registry concerns.
randomSerial in internal/proxy/tls.go
Function: randomSerial() *big.Int
Issue: Crypto-random primitive embedded in proxy-specific TLS file.
Recommendation: Consolidate with similar crypto-random helpers if they exist, or document that it's intentionally local to certificate assembly.
Similarity: Both extract owner/repo/username fields from map[string]interface{} tool arguments with the same util.GetStringFromMap pattern and similar error shaping.
Recommendation: Create a small typed arg-decoding helper in internal/util/ or internal/githubhttp/ for common owner/repo/number/username patterns.
Similarity: Both persist in-memory state to JSON files using identical init/fallback/write lifecycle patterns.
Recommendation: Extract a shared statefulJSONLogger base helper within internal/logger/ to remove repeated scaffolding.
3. Scattered Filesystem-Write Helpers
Theme: Directory creation, permission handling, and file-write semantics are duplicated across logging, payload storage, sessions, and TLS generation.
Location
Function
Pattern
internal/logger/fileutil.go
atomicWriteFile, writeJSONToFile
Atomic write + chmod
internal/middleware/jqschema.go
savePayload
MkdirAll + WriteFile
internal/server/session.go
ensureSessionDirectory
MkdirAll + permission check
internal/proxy/tls.go
writePEM
MkdirAll + WriteFile
Recommendation: Evaluate whether a shared internal/fileutil (or extending internal/logger/fileutil.go) for mkdir/write/chmod/atomic-write patterns would reduce duplication and simplify error handling.
Refactoring Recommendations
Priority 1: High Impact
Consolidate session ID extraction β Ensure ExtractSessionIDFromHeaders is the single canonical implementation, with extractSessionIDFromRequest being a clear, minimal wrapper. Estimated effort: ~30 min.
Move GenerateRandomAgentID β Relocate to internal/util/random.go for consistency with other random utilities. Estimated effort: ~30 min.
π§ Semantic Function Clustering Analysis
Analysis of repository: github/gh-aw-mcpg β Β§29703870629
Executive Summary
Analysis of 158 Go source files (excluding test files) across the
internal/directory cataloged 956 functions. The codebase is overall well-organized with clear package boundaries, but four categories of refactoring opportunities were identified: outlier functions that don't belong in their current files, near-duplicate extraction patterns, redundant filesystem-write scaffolding, and scattered typed-argument-decoding helpers.No severe disorganization was found β findings are moderate-impact improvements targeting code centralization and cleaner separation of concerns.
Identified Issues
1. Outlier Functions (Functions in Wrong Files)
GenerateRandomAgentIDininternal/auth/header.goGenerateRandomAgentID() (string, error)internal/util/random.go(already has random utilities) or a dedicatedinternal/auth/id.go.parseServerIDFromToolNameininternal/middleware/jqschema.goparseServerIDFromToolName(toolName string) stringinternal/server/tool registry concerns.randomSerialininternal/proxy/tls.gorandomSerial() *big.Int2. Near-Duplicate Functions
Session ID extraction duplication
internal/auth/header.go:ExtractSessionIDFromHeaders(xAgentID, authHeader string) stringinternal/server/session.go:extractSessionIDFromRequest(r *http.Request) stringX-Agent-ID/Authorization; the server wrapper adds only HTTP request field access.internal/auth/and make the server-layer wrapper clearly minimal (a single-line delegating call).Integer env-var parsing duplication
internal/envutil/envutil.go:GetEnvInt(...)(generic)internal/config/gateway_env.go:parseAndValidateIntEnv(envKey string, validate func(int) *ValidationError)(policy-aware)ParseEnvInt/ValidateEnvInthelpers;gateway_envprovides thin policy wrappers only.Typed argument-map extraction duplication
internal/proxy/router.go:extractOwnerRepoNumber(...)internal/githubhttp/collaborator.go:ParseCollaboratorPermissionArgs(...)map[string]interface{}tool arguments with the sameutil.GetStringFromMappattern and similar error shaping.internal/util/orinternal/githubhttp/for common owner/repo/number/username patterns.JSON-backed state logger scaffolding duplication
internal/logger/tools_logger.go:writeToFileinternal/logger/observed_url_domains_logger.go:writeToFilestatefulJSONLoggerbase helper withininternal/logger/to remove repeated scaffolding.3. Scattered Filesystem-Write Helpers
Theme: Directory creation, permission handling, and file-write semantics are duplicated across logging, payload storage, sessions, and TLS generation.
internal/logger/fileutil.goatomicWriteFile,writeJSONToFileinternal/middleware/jqschema.gosavePayloadinternal/server/session.goensureSessionDirectoryinternal/proxy/tls.gowritePEMRecommendation: Evaluate whether a shared
internal/fileutil(or extendinginternal/logger/fileutil.go) for mkdir/write/chmod/atomic-write patterns would reduce duplication and simplify error handling.Refactoring Recommendations
Priority 1: High Impact
Consolidate session ID extraction β Ensure
ExtractSessionIDFromHeadersis the single canonical implementation, withextractSessionIDFromRequestbeing a clear, minimal wrapper. Estimated effort: ~30 min.Move
GenerateRandomAgentIDβ Relocate tointernal/util/random.gofor consistency with other random utilities. Estimated effort: ~30 min.Extract shared JSON-state logger scaffolding β Deduplicate
writeToFilepattern ininternal/logger/. Estimated effort: ~1β2 hours.Priority 2: Medium Impact
Centralize typed tool-argument decoding β Create reusable owner/repo/username extractor helpers. Estimated effort: ~2β3 hours.
Shared filesystem-write utilities β Audit and consolidate file-write patterns across logger, middleware, server, proxy. Estimated effort: ~2β4 hours.
Extract
parseServerIDFromToolNameβ Move to a tool-name utility module. Estimated effort: ~30 min.Priority 3: Long-term Improvements
Implementation Checklist
ExtractSessionIDFromHeaders/extractSessionIDFromRequestduplicationGenerateRandomAgentIDtointernal/util/random.gowriteToFileininternal/logger/parseServerIDFromToolNameto tool-name utilitiesAnalysis Metadata
References:
Warning
Firewall blocked 2 domains
The following domains were blocked by the firewall during workflow execution:
awmgmcpgproxy.golang.orgSee Network Configuration for more information.