Refactor: Move logger helpers and flag completions to correct files#1196
Merged
Refactor: Move logger helpers and flag completions to correct files#1196
Conversation
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses organizational inconsistencies in the codebase by moving helper functions to their correct locations according to established package patterns. The refactoring was identified through static analysis and restores consistency without any behavioral changes.
Changes:
- Moved ToolsLogger init/close helpers from
tools_logger.gotoglobal_helpers.goto match all other logger types - Updated
common.godocumentation to include ToolsLogger helpers in the canonical list - Moved
registerFlagCompletionsfromroot.gotoflags.goto centralize flag-related logic
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/logger/tools_logger.go | Removed initGlobalToolsLogger and closeGlobalToolsLogger helper functions (moved to global_helpers.go) |
| internal/logger/global_helpers.go | Added initGlobalToolsLogger and closeGlobalToolsLogger helper functions to match pattern of all other logger types |
| internal/logger/common.go | Updated documentation to include initGlobalToolsLogger() in the canonical list of global helper functions |
| internal/cmd/root.go | Removed registerFlagCompletions function (moved to flags.go) |
| internal/cmd/flags.go | Added registerFlagCompletions function to centralize all flag-related logic |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
lpcox
added a commit
that referenced
this pull request
Feb 20, 2026
- [x] Fix Serena tools configuration in smoke-copilot.md (change nested languages structure to array format) - [x] Recompile smoke-copilot workflow to regenerate lock file - [x] Verify the fix matches working configurations in other workflows - [x] Store memory about correct Serena tool configuration format <!-- START COPILOT ORIGINAL PROMPT --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>Smoke Test: Copilot - 22243401416</issue_title> > <issue_description>## Smoke Test Results > > | Test | Status | > |------|--------| > | GitHub MCP - Last 2 merged PRs | ✅ PR #1195 "Fix Serena MCP test tool discovery in smoke test workflow", PR #1186 "Eliminate duplicate code in server HTTP endpoint registration" | > | Safe Inputs GH CLI - 2 PRs | ✅ PR #1196 "[WIP] Refactor semantic function clustering for code organization" | > | Serena MCP - activate_project + find_symbol | ❌ Tools not available in this agent context | > | Make Build | ✅ `make build` succeeded, `awmg` binary produced | > | Playwright - github.com title | ✅ Title contains "GitHub" | > | File Writing | ✅ `/tmp/gh-aw/agent/smoke-test-copilot-22243401416.txt` created | > | Bash Tool | ✅ File read back successfully | > | Discussion Interaction | ✅ Comment added to discussion #45 | > | Agentic Workflows MCP Status | ✅ smoke-copilot: compiled=Yes, triggers=PR/reaction/schedule | > > ## Overall Status:⚠️ PARTIAL PASS (8/9 tests passed, Serena tools unavailable) > > **Run URL**: https://github.com/github/gh-aw-mcpg/actions/runs/22243401416 > **Timestamp**: 2026-02-20T22:21 UTC > > > > > > 📰 *BREAKING: Report filed by [Smoke Copilot](https://github.com/github/gh-aw-mcpg/actions/runs/22243401416)* > > - [x] expires <!-- gh-aw-expires: 2026-02-21T00:23:33.836Z --> on Feb 21, 2026, 12:23 AM UTC > > <!-- gh-aw-agentic-workflow: Smoke Copilot, engine: copilot, run: https://github.com/github/gh-aw-mcpg/actions/runs/22243401416 --> > > <!-- gh-aw-workflow-id: smoke-copilot --></issue_description> > > <agent_instructions>Figure out why serena is not passing</agent_instructions> > > ## Comments on the Issue (you are @claude[agent] in this section) > > <comments> > </comments> > </details> <!-- START COPILOT CODING AGENT SUFFIX --> - Fixes #1198
This was referenced Feb 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Static analysis identified two organizational inconsistencies where helper functions were placed in the wrong files, breaking established package patterns.
Changes
Logger Package (
internal/logger/)initGlobalToolsLogger()andcloseGlobalToolsLogger()fromtools_logger.gotoglobal_helpers.gocommon.goto include ToolsLogger helpers in the canonical listPreviously, all logger init/close helpers (FileLogger, JSONLLogger, MarkdownLogger, ServerFileLogger) were in
global_helpers.go, but ToolsLogger's helpers were outliers intools_logger.go. This change restores consistency:CMD Package (
internal/cmd/)registerFlagCompletions()fromroot.gotoflags.goThe
flags.gofile centralizes all flag-related logic (RegisterFlag,registerAllFlags). The completion registration function was misplaced inroot.go.Impact
Pure code organization refactoring with zero behavioral changes. All tests pass.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/tmp/go-build3536313155/b275/launcher.test /tmp/go-build3536313155/b275/launcher.test -test.testlogfile=/tmp/go-build3536313155/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -c=4 -nolocalimports -importcfg /tmp/go-build3536313155/b256/importcfg -pack /home/REDACTED/go/pkg/mod/github.com/itchyny/gojq@v0.12.18/builtin.go /home/REDACTED/go/pkg/mod/github.com/itchyny/gojq@v0.12.18/code.go rev-�� go HEAD x_amd64/compile(dns block)/tmp/go-build32475415/b279/launcher.test /tmp/go-build32475415/b279/launcher.test -test.testlogfile=/tmp/go-build32475415/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -lang=go1.25 01.o .cfg 64/src/net --gdwarf-5 64/pkg/tool/linu/tmp/go-build3223519424/b241/vet.cfg sh -c git status --porcelain --ignore-submodules | head -n 10 64/pkg/tool/linuHEAD ache/go/1.25.6/x64/pkg/tool/linux_amd64/compile -unreachable=fal/usr/bin/runc.original 6313155/b165/ cal/bin/as ache/go/1.25.6/x64/pkg/tool/linux_amd64/compile(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build3536313155/b260/config.test /tmp/go-build3536313155/b260/config.test -test.testlogfile=/tmp/go-build3536313155/b260/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go ternal/randutil/--gdwarf2 64/pkg/tool/linu--64(dns block)/tmp/go-build32475415/b264/config.test /tmp/go-build32475415/b264/config.test -test.testlogfile=/tmp/go-build32475415/b264/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true --abbrev-ref HEAD ache/Python/3.12.12/x64/git lcache/go/1.25.6/opt/hostedtoolcache/go/1.25.6/x64/pkg/tool/linux_amd64/compile .cfg 64/pkg/tool/linu/tmp/go-build3223519424/b260/_pkg_.a base64 -d -lang=go1.25 64/pkg/tool/linugithub.com/github/gh-aw-mcpg/internal/testutil/mcptest /usr/local/.ghcu-lang=go1.25 v0.12.18/builtin/opt/hostedtoolcache/go/1.25.6/x64/pkg/tool/linux_amd64/vet v0.12.18/code.go-unsafeptr=false 64/pkg/tool/linu/tmp/go-build3223519424/b186/vet.cfg git(dns block)nonexistent.local/tmp/go-build3536313155/b275/launcher.test /tmp/go-build3536313155/b275/launcher.test -test.testlogfile=/tmp/go-build3536313155/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -c=4 -nolocalimports -importcfg /tmp/go-build3536313155/b256/importcfg -pack /home/REDACTED/go/pkg/mod/github.com/itchyny/gojq@v0.12.18/builtin.go /home/REDACTED/go/pkg/mod/github.com/itchyny/gojq@v0.12.18/code.go rev-�� go HEAD x_amd64/compile(dns block)/tmp/go-build32475415/b279/launcher.test /tmp/go-build32475415/b279/launcher.test -test.testlogfile=/tmp/go-build32475415/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -lang=go1.25 01.o .cfg 64/src/net --gdwarf-5 64/pkg/tool/linu/tmp/go-build3223519424/b241/vet.cfg sh -c git status --porcelain --ignore-submodules | head -n 10 64/pkg/tool/linuHEAD ache/go/1.25.6/x64/pkg/tool/linux_amd64/compile -unreachable=fal/usr/bin/runc.original 6313155/b165/ cal/bin/as ache/go/1.25.6/x64/pkg/tool/linux_amd64/compile(dns block)slow.example.com/tmp/go-build3536313155/b275/launcher.test /tmp/go-build3536313155/b275/launcher.test -test.testlogfile=/tmp/go-build3536313155/b275/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -c=4 -nolocalimports -importcfg /tmp/go-build3536313155/b256/importcfg -pack /home/REDACTED/go/pkg/mod/github.com/itchyny/gojq@v0.12.18/builtin.go /home/REDACTED/go/pkg/mod/github.com/itchyny/gojq@v0.12.18/code.go rev-�� go HEAD x_amd64/compile(dns block)/tmp/go-build32475415/b279/launcher.test /tmp/go-build32475415/b279/launcher.test -test.testlogfile=/tmp/go-build32475415/b279/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -lang=go1.25 01.o .cfg 64/src/net --gdwarf-5 64/pkg/tool/linu/tmp/go-build3223519424/b241/vet.cfg sh -c git status --porcelain --ignore-submodules | head -n 10 64/pkg/tool/linuHEAD ache/go/1.25.6/x64/pkg/tool/linux_amd64/compile -unreachable=fal/usr/bin/runc.original 6313155/b165/ cal/bin/as ache/go/1.25.6/x64/pkg/tool/linux_amd64/compile(dns block)this-host-does-not-exist-12345.com/tmp/go-build3536313155/b284/mcp.test /tmp/go-build3536313155/b284/mcp.test -test.testlogfile=/tmp/go-build3536313155/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true go ternal/fips140/t--gdwarf2 64/pkg/tool/linu--64(dns block)Co-authored-by: lgithub.com/github/gh-aw-mcpg/int/usr/bin/runc /home/REDACTED/work/temp/ghcca-node/node/bin/git g.a 6313155/b165/ /opt/hostedtoolcache/uv/0.10.4/x-x git rev-�� --abbrev-ref HEAD x_amd64/vet #^vebash -I tnet/tools/as x_amd64/vet` (dns block)
Original prompt
This section details on the original issue you should resolve
<issue_title>[refactor] Semantic Function Clustering Analysis — Refactoring Opportunities</issue_title>
<issue_description>## Overview
Static analysis of all 65 non-test Go files in
internal/identified four actionable refactoring opportunities. Two large files exceed 1000 lines and mix distinct concerns (mcp/connection.go,server/unified.go). One package-wide inconsistency exists in thelogger/package where global helpers forToolsLoggerare misplaced. One utility function (registerFlagCompletions) is in the wrong file incmd/.Overall code organization is good — packages are purposefully structured, test utilities are separated, and the config, difc, guard, and auth packages are well-organized. The issues below are high-signal, actionable improvements.
Analysis Metadata
internal/+ root)Identified Issues
1. 🔴 Outlier:
initGlobalToolsLogger/closeGlobalToolsLoggerintools_logger.goPriority: High — This breaks an established, documented pattern.
Issue: Every other global logger init/close helper pair lives in
global_helpers.go:initGlobalFileLogger/closeGlobalFileLogger→global_helpers.goinitGlobalJSONLLogger/closeGlobalJSONLLogger→global_helpers.goinitGlobalMarkdownLogger/closeGlobalMarkdownLogger→global_helpers.goinitGlobalServerFileLogger/closeGlobalServerFileLogger→global_helpers.goinitGlobalToolsLogger/closeGlobalToolsLogger→tools_logger.go← outlierThe file
common.goeven explicitly documents this pattern and lists all helpers expected to be inglobal_helpers.go(lines 164–167), butToolsLogger's helpers are missing from that list.Recommendation: Move
initGlobalToolsLoggerandcloseGlobalToolsLoggerfromtools_logger.gotoglobal_helpers.go, and add them to the documentation list incommon.go. Estimated effort: 15 minutes.2. 🔴 Monolith:
mcp/connection.go(1010 lines, 5 distinct concerns)Priority: High — A single file handles five distinct responsibilities.
Responsibilities currently mixed in
connection.go:parseSSEResponse,parseJSONRPCResponseWithSSE,isHTTPConnectionErrorNewConnection,NewHTTPConnection,newMCPClient,newHTTPConnection,trySDKTransport,tryStreamableHTTPTransport,trySSETransport,tryPlainJSONTransportcreateJSONRPCRequest,ensureToolCallArguments,setupHTTPRequest,executeHTTPRequest,sendHTTPRequest,initializeHTTPSessionlistTools,callTool,listResources,readResource,listPrompts,getPromptexpandDockerEnvArgs,containsEqualSpecific outlier:
expandDockerEnvArgsandcontainsEqualprocess Docker--envargument formatting. They are conceptually Docker launch utilities, not connection logic. They would fit better in thelauncher/package or in a dedicatedinternal/mcp/docker.gofile.Recommendation:
internal/mcp/docker_env.go(or move tolauncher/)internal/mcp/http_request.go3. 🟡 Monolith:
server/unified.go(1037 lines, 4 distinct concerns)Priority: Medium — A single file handles session management, tool registration, tool calling, and server lifecycle.
Responsibilities currently mixed in
unified.go:NewSession,getSessionID,requireSession,getSessionKeys,ensureSessionDirectoryregisterAllTools,registerAllToolsSequential,registerAllToolsParallel,registerToolsFromBackend,registerSysTools,registerGuardcallBackendTool,convertToCallToolResult,newErrorCallToolResult,parseToolArgumentsNewUnified,Run,Close,IsShutdown,InitiateShutdown,GetServerIDs,GetServerStatus,GetToolsForBackend,GetToolHandler,GetPayloadSizeThreshold,IsDIFCEnabledRegisterTestTool,SetTestMode,ShouldExitRecommendation:
internal/server/session.go(theSessionstruct and its lifecycle functions already form a natural unit)internal/server/tool_registry.go4. 🟡 Outlier:
registerFlagCompletionsincmd/root.goPriority: Low...