Skip to content

Refactor utility placement: move shared helpers out of specialized files and remove micro-packages/files#4117

Merged
lpcox merged 3 commits intomainfrom
copilot/refactor-semantic-function-clustering
Apr 18, 2026
Merged

Refactor utility placement: move shared helpers out of specialized files and remove micro-packages/files#4117
lpcox merged 3 commits intomainfrom
copilot/refactor-semantic-function-clustering

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 18, 2026

Semantic clustering flagged utility outliers and micro-file/package sprawl across internal/. This PR consolidates shared helpers into appropriate common packages and removes single-purpose file/package fragmentation while preserving existing behavior.

  • Version composition moved to internal/version

    • Extracted buildVersionString from main.go into version.BuildVersionString(mainVersion, gitCommit, buildDate).
    • main now delegates version-string assembly to internal/version, making logic package-local and testable outside main.
  • Transient HTTP classification centralized in httputil

    • Promoted config-local isTransientHTTPError to shared httputil.IsTransientHTTPError.
    • Updated config schema fetch retry path to call the shared helper.
    • Moved associated test coverage from internal/config to internal/httputil.
  • Removed timeutil micro-package

    • Moved FormatDuration from internal/timeutil to internal/strutil.
    • Updated logger time-diff formatting call sites to strutil.FormatDuration.
    • Deleted internal/timeutil files.
  • Collapsed micro-files in auth and oidc

    • Merged GenerateRandomAPIKey (and logger) into internal/auth/header.go; removed internal/auth/apikey.go.
    • Merged ErrMissingOIDCEnvVar into internal/oidc/provider.go; removed internal/oidc/errors.go.
  • Inlined single-use logger helper

    • Removed getMapKeys from internal/logger/rpc_helpers.go.
    • Inlined key extraction at the call site and dropped now-obsolete unit test for that private helper.
  • Docs alignment

    • Updated package-structure docs to reflect removal of internal/timeutil and expanded internal/strutil role.
// before (main.go)
versionStr := buildVersionString()

// after
versionStr := version.BuildVersionString(Version, GitCommit, BuildDate)

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
    • Triggering command: /tmp/go-build3787159813/b514/launcher.test /tmp/go-build3787159813/b514/launcher.test -test.testlogfile=/tmp/go-build3787159813/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3787159813/b423/vet.cfg rotocol/go-sdk@v1.5.0/jsonrpc/jsonrpc.go =0 x_amd64/vet --gdwarf-5 esource/v1 -o x_amd64/vet --de�� _.a --debug-prefix-m-ifaceassert x_amd64/vet -I go-sdk/mcp -I x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build2056270914/b513/launcher.test /tmp/go-build2056270914/b513/launcher.test -test.testlogfile=/tmp/go-build2056270914/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s know�� known-linux-gnu/lib/rustlib/x86_/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rustgit known-linux-gnu/lib/rustlib/x86_/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rustpush x_amd64/compile known-linux-gnu/git known-linux-gnu/ls-files known-linux-gnu/--exclude-standard x_amd64/compile know�� known-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libminiz_oxide-2b6a8d2f6e1dc71b.rlib known-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libadler2-39ffdbc27c978ccc.rlib /opt/containerd/bin/bash /run/containerd/git 7213e0dede2210feconfig json 7213e0dede2210fed31/init.pid (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3787159813/b496/config.test /tmp/go-build3787159813/b496/config.test -test.testlogfile=/tmp/go-build3787159813/b496/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3787159813/b317/vet.cfg @v1.1.3/cpu/cpu.-errorsas 89155655/b151//_-ifaceassert x_amd64/vet --gdwarf-5 --64 155655/b151/ x_amd64/vet -w ache/go/1.25.8/x-errorsas dHAhgBmen x_amd64/vet OUTPUT -d ut-3746032072.c x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build1806864329/b491/config.test /tmp/go-build1806864329/b491/config.test -test.testlogfile=/tmp/go-build1806864329/b491/testlog.txt -test.paniconexit0 -test.timeout=10m0s bug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.04.rcgu-importcfg bug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.05.rcgu/tmp/go-build1806864329/b237/importcfg bug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.06.rcgu-pack bug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.07.rcgu/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/internal/difc/agent.go bug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.08.rcgu/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/internal/difc/capabilities.go bug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.09.rcgu.o bug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.10.rcgu.o bug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.11.rcgu.o bug/�� bug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.13.rcgu.o bug/deps/serde_derive-bdc7cd22a58a5141.serde_derive.12123747d8da05ed-cgu.14.rcgu.o -guard/target/de--build-id ntime.v2.task/mo/opt/copilot-runtime/copilot-developer-action-main/dist/ripgrep/bin/linux-x64/rg-trimpath /tmp/go-build389--files lib/rustlib/x86_--hidden lib/rustlib/x86_--glob (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build3787159813/b514/launcher.test /tmp/go-build3787159813/b514/launcher.test -test.testlogfile=/tmp/go-build3787159813/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3787159813/b423/vet.cfg rotocol/go-sdk@v1.5.0/jsonrpc/jsonrpc.go =0 x_amd64/vet --gdwarf-5 esource/v1 -o x_amd64/vet --de�� _.a --debug-prefix-m-ifaceassert x_amd64/vet -I go-sdk/mcp -I x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build2056270914/b513/launcher.test /tmp/go-build2056270914/b513/launcher.test -test.testlogfile=/tmp/go-build2056270914/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s know�� known-linux-gnu/lib/rustlib/x86_/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rustgit known-linux-gnu/lib/rustlib/x86_/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rustpush x_amd64/compile known-linux-gnu/git known-linux-gnu/ls-files known-linux-gnu/--exclude-standard x_amd64/compile know�� known-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libminiz_oxide-2b6a8d2f6e1dc71b.rlib known-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libadler2-39ffdbc27c978ccc.rlib /opt/containerd/bin/bash /run/containerd/git 7213e0dede2210feconfig json 7213e0dede2210fed31/init.pid (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build3787159813/b514/launcher.test /tmp/go-build3787159813/b514/launcher.test -test.testlogfile=/tmp/go-build3787159813/b514/testlog.txt -test.paniconexit0 -test.timeout=10m0s /tmp/go-build3787159813/b423/vet.cfg rotocol/go-sdk@v1.5.0/jsonrpc/jsonrpc.go =0 x_amd64/vet --gdwarf-5 esource/v1 -o x_amd64/vet --de�� _.a --debug-prefix-m-ifaceassert x_amd64/vet -I go-sdk/mcp -I x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build2056270914/b513/launcher.test /tmp/go-build2056270914/b513/launcher.test -test.testlogfile=/tmp/go-build2056270914/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s know�� known-linux-gnu/lib/rustlib/x86_/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rustgit known-linux-gnu/lib/rustlib/x86_/home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/guards/github-guard/rustpush x_amd64/compile known-linux-gnu/git known-linux-gnu/ls-files known-linux-gnu/--exclude-standard x_amd64/compile know�� known-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libminiz_oxide-2b6a8d2f6e1dc71b.rlib known-linux-gnu/lib/rustlib/x86_64-REDACTED-linux-gnu/lib/libadler2-39ffdbc27c978ccc.rlib /opt/containerd/bin/bash /run/containerd/git 7213e0dede2210feconfig json 7213e0dede2210fed31/init.pid (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build3787159813/b523/mcp.test /tmp/go-build3787159813/b523/mcp.test -test.testlogfile=/tmp/go-build3787159813/b523/testlog.txt -test.paniconexit0 -test.timeout=10m0s -W cfg /tmp/go-build389-ifaceassert x_amd64/vet _amd64.s g/protobuf/proto--version --64 x_amd64/vet cfg 155655/b281/_pkg_.a -fPIC x_amd64/vet -pthread .io/otel/exporte/usr/bin/runc -fmessage-length--version x_amd64/vet (dns block)
    • Triggering command: /tmp/go-build2056270914/b522/mcp.test /tmp/go-build2056270914/b522/mcp.test -test.testlogfile=/tmp/go-build2056270914/b522/testlog.txt -test.paniconexit0 -test.timeout=10m0s go1.25.8 -c=4 -nolocalimports -importcfg /tmp/go-build3333051407/b001/importcfg -pack /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/main.go /home/REDACTED/work/gh-aw-mcpg/gh-aw-mcpg/version.go ive.�� ive.12123747d8da05ed-cgu.02.rcgugo1.25.8 ive.12123747d8da05ed-cgu.03.rcgu-c=4 ive.12123747d8da05ed-cgu.04.rcgu-nolocalimports ive.12123747d8da/opt/hostedtoolcache/go/1.25.8/x64/pkg/tool/linux_amd64/link ive.12123747d8da-V=full ive.12123747d8da05ed-cgu.07.rcgu-bool ive.12123747d8da05ed-cgu.08.rcgu-buildtags (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Refactor semantic function clustering analysis outliers and micro-files Refactor utility placement: move shared helpers out of specialized files and remove micro-packages/files Apr 18, 2026
Copilot AI requested a review from lpcox April 18, 2026 17:24
@lpcox lpcox marked this pull request as ready for review April 18, 2026 17:40
Copilot AI review requested due to automatic review settings April 18, 2026 17:40
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reduces internal/ micro-package/file sprawl by relocating shared helpers into common utility packages and consolidating single-purpose code into existing files, keeping behavior consistent while improving reuse and discoverability.

Changes:

  • Moved version-string composition into internal/version via version.BuildVersionString(...) and updated main + tests.
  • Centralized transient HTTP status retry classification into internal/httputil.IsTransientHTTPError and updated config schema-fetch retry logic + tests.
  • Removed internal/timeutil by moving FormatDuration to internal/strutil, updated logger call sites, and collapsed micro-files in auth/oidc/logger helpers.
Show a summary per file
File Description
main.go Switches version string assembly to version.BuildVersionString(...); removes local helper.
main_test.go Updates tests to call version.BuildVersionString(...).
internal/version/version.go Adds BuildVersionString implementation alongside existing version storage helpers.
internal/httputil/httputil.go Adds shared IsTransientHTTPError helper.
internal/httputil/transient_http_error_test.go Moves/updates tests to validate IsTransientHTTPError.
internal/config/validation_schema.go Uses httputil.IsTransientHTTPError in schema fetch retry logic.
internal/strutil/format_duration.go Moves duration formatting into strutil.
internal/strutil/format_duration_test.go Updates duration formatting tests to strutil package.
internal/logger/logger.go Updates duration formatting call sites to strutil.FormatDuration.
internal/logger/rpc_helpers.go Inlines map key extraction and removes now-unneeded private helper.
internal/logger/rpc_helpers_test.go Removes unit test for deleted private helper.
internal/auth/header.go Inlines API key generator into header.go (and keeps logging local).
internal/auth/apikey.go Removes micro-file now merged into header.go.
internal/oidc/provider.go Inlines ErrMissingOIDCEnvVar into provider implementation.
internal/oidc/errors.go Removes micro-file now merged into provider.go.
CONTRIBUTING.md Updates package-structure docs for strutil expansion and timeutil removal.
AGENTS.md Updates quick project-structure reference to reflect utility consolidation.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 17/17 changed files
  • Comments generated: 1

Comment thread CONTRIBUTING.md
Comment on lines 293 to 299
- **`internal/oidc/`** - OIDC authentication for HTTP MCP backends
- **`internal/proxy/`** - HTTP forward proxy applying DIFC filtering to `gh` CLI and REST/GraphQL requests
- **`internal/server/`** - HTTP server with routed and unified modes
- **`internal/strutil/`** - String utility helpers (deduplication, trimming)
- **`internal/strutil/`** - String and formatting utility helpers (deduplication, trimming, duration formatting)
- **`internal/syncutil/`** - Concurrency utility helpers (get-or-create pattern)
- **`internal/sys/`** - System utilities
- **`internal/testutil/`** - Test utilities and helpers
Copy link

Copilot AI Apr 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This update removes internal/timeutil from the “Key Directories” list, but the earlier “Project Structure” tree in the same document still lists internal/timeutil/ and describes internal/strutil/ only as string helpers. Please update that tree block as well so the structure documentation is consistent with the refactor.

Copilot uses AI. Check for mistakes.
@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented Apr 18, 2026

@copilot address the review feedback #4117 (review)

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 18, 2026

@copilot address the review feedback #4117 (review)

Addressed in d6c0c9a. I updated the CONTRIBUTING.md Project Structure tree to remove internal/timeutil and changed strutil to “String and formatting utility helpers” so it now matches the Key Directories section.

@lpcox lpcox merged commit 18b19a6 into main Apr 18, 2026
13 checks passed
@lpcox lpcox deleted the copilot/refactor-semantic-function-clustering branch April 18, 2026 17:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] Semantic Function Clustering Analysis — Outliers, Micro-files, and Consolidation Opportunities

3 participants