Commit 4e4c19f
authored
Document constructor naming conventions per semantic analysis (#818)
Semantic analysis identified inconsistent constructor patterns across
the codebase and recommended documentation. Analysis also surfaced
opportunities for file extraction (unified.go: 1032 lines,
connection.go: 1009 lines) and RPC logger consolidation.
## Changes
### Constructor Naming Conventions (CONTRIBUTING.md)
Documented three patterns with usage criteria and real examples:
```go
// Simple object creation - no errors
func NewConnection(ctx context.Context) *Connection
// Factory with registry lookup or complex init
func CreateGuard(name string) (Guard, error)
// Global singleton initialization
func InitFileLogger(dir string) error
```
Includes 35+ real examples from codebase and decision flow.
### Follow-up Work Items
Created structured proposals for code refactorings (each ~4-6 hours):
- **unified.go extraction** → 4 files: registration (~250L), session
(~150L), tools (~200L), core (~400L)
- **connection.go extraction** → 4 files: http (~350L), transport
(~250L), tools (~200L), core (~200L)
- **RPC logger consolidation** → `internal/logger/rpc/` subdirectory
Each includes implementation plan, benefits, and context for future
sessions with proper incremental testing.
## Rationale
Semantic analysis marked refactorings as "optional enhancements."
Delivered immediate value (documentation) and actionable future work
(proposals) rather than rushing complex refactorings that require
careful testing.
> [!WARNING]
>
> <details>
> <summary>Firewall rules blocked me from connecting to one or more
addresses (expand for details)</summary>
>
> #### I tried to connect to the following addresses, but was blocked by
firewall rules:
>
> - `example.com`
> - Triggering command: `/tmp/go-build889290460/b275/launcher.test
/tmp/go-build889290460/b275/launcher.test
-test.testlogfile=/tmp/go-build889290460/b275/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
p=/opt/hostedtoolcache/go/1.25.6/x64=/_/GOROOT 6945474/b098/ x_amd64/vet
--gdwarf-5 --64 -o x_amd64/vet 6945�� submodules | head -n 10
6945474/b098/ x_amd64/vet
/tmp/go-build409/opt/hostedtoolcache/go/1.25.6/x64/pkg/tool/linux_amd64/vet
-imultiarch x86_64-linux-gnu-unreachable=false x_amd64/vet` (dns block)
> - `invalid-host-that-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build889290460/b260/config.test
/tmp/go-build889290460/b260/config.test
-test.testlogfile=/tmp/go-build889290460/b260/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true E=3 IBUTING.md
Co-authored-by: lpcox
<15877973+lpcox@users.noreply.github.com> x_amd64/compile
6945474/b105/ --64 -o x_amd64/compile 6945�� is 6945474/b098/
x_amd64/vet -pthread -Wl,--no-gc-sect-unsafeptr=false
-fmessage-length-unreachable=false x_amd64/vet` (dns block)
> - `nonexistent.local`
> - Triggering command: `/tmp/go-build889290460/b275/launcher.test
/tmp/go-build889290460/b275/launcher.test
-test.testlogfile=/tmp/go-build889290460/b275/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
p=/opt/hostedtoolcache/go/1.25.6/x64=/_/GOROOT 6945474/b098/ x_amd64/vet
--gdwarf-5 --64 -o x_amd64/vet 6945�� submodules | head -n 10
6945474/b098/ x_amd64/vet
/tmp/go-build409/opt/hostedtoolcache/go/1.25.6/x64/pkg/tool/linux_amd64/vet
-imultiarch x86_64-linux-gnu-unreachable=false x_amd64/vet` (dns block)
> - `slow.example.com`
> - Triggering command: `/tmp/go-build889290460/b275/launcher.test
/tmp/go-build889290460/b275/launcher.test
-test.testlogfile=/tmp/go-build889290460/b275/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
p=/opt/hostedtoolcache/go/1.25.6/x64=/_/GOROOT 6945474/b098/ x_amd64/vet
--gdwarf-5 --64 -o x_amd64/vet 6945�� submodules | head -n 10
6945474/b098/ x_amd64/vet
/tmp/go-build409/opt/hostedtoolcache/go/1.25.6/x64/pkg/tool/linux_amd64/vet
-imultiarch x86_64-linux-gnu-unreachable=false x_amd64/vet` (dns block)
> - `this-host-does-not-exist-12345.com`
> - Triggering command: `/tmp/go-build889290460/b284/mcp.test
/tmp/go-build889290460/b284/mcp.test
-test.testlogfile=/tmp/go-build889290460/b284/testlog.txt
-test.paniconexit0 -test.timeout=10m0s -test.v=true
p=/opt/hostedtoolcache/go/1.25.6-p 6945474/b098/ x_amd64/vet --gdwarf-5
--64 -o x_amd64/vet 6945�� 6945474/b182/_pkg_.a
/opt/hostedtoolcache/go/1.25.6/x-c=4 x_amd64/vet
/tmp/go-build409/opt/hostedtoolcache/go/1.25.6/x64/pkg/tool/linux_amd64/vet
-imultiarch x86_64-linux-gnu-unreachable=false x_amd64/vet` (dns block)
>
> If you need me to access, download, or install something from one of
these locations, you can either:
>
> - Configure [Actions setup
steps](https://gh.io/copilot/actions-setup-steps) to set up my
environment, which run before the firewall is enabled
> - Add the appropriate URLs or hosts to the custom allowlist in this
repository's [Copilot coding agent
settings](https://github.com/github/gh-aw-mcpg/settings/copilot/coding_agent)
(admins only)
>
> </details>
<!-- START COPILOT ORIGINAL PROMPT -->
<details>
<summary>Original prompt</summary>
----
*This section details on the original issue you should resolve*
<issue_title>[refactor] Enhanced Semantic Analysis - Deep Refactoring
Opportunities</issue_title>
<issue_description>## 🔧 Enhanced Semantic Function Clustering Analysis
*Analysis performed on repository: github/gh-aw-mcpg*
*Analysis date: 2026-02-07*
*Total Go files analyzed: 68 files (including root-level files)*
*Total functions cataloged: ~225+ non-test functions*
---
## Executive Summary
This analysis builds upon previous refactoring work and identifies **NEW
opportunities** for code organization improvements. The codebase
maintains excellent overall structure, but several patterns emerge that
suggest targeted refactoring could improve maintainability and reduce
cognitive load.
**Key New Findings:**
- ✅ **Strong functional organization** - Most files maintain single
responsibility
- 1 file changed
Lines changed: 73 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
246 | 246 | | |
247 | 247 | | |
248 | 248 | | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
249 | 322 | | |
250 | 323 | | |
251 | 324 | | |
| |||
0 commit comments