Conversation
- health_command.go: Replace O(n²) bubble sort with slices.SortFunc for workflow health sorting (cleaner, more efficient, uses standard library) - compile_config.go: Use sliceutil.Map for nested validation result sanitization, extracting a pure sanitizeError helper function to make the transformation declarative and composable - logs_report.go: Replace all sort.Slice/sort.Strings calls with slices.SortFunc/slices.Sort from the standard slices package for type-safe, index-free comparisons; removes sort package dependency Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
pelikhan
approved these changes
Mar 10, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR modernizes pkg/cli by replacing index-based sorting and imperative slice transformations with Go’s slices/cmp helpers and a small functional mapping utility, improving readability and reducing algorithmic complexity where applicable.
Changes:
- Replaced a manual bubble sort with
slices.SortFunc+cmp.Comparein health summary sorting. - Refactored validation result sanitization to a pure helper + nested
sliceutil.Maptransforms. - Migrated multiple
sort.Slice/sort.Stringsusages toslices.SortFunc/slices.Sort, removing thesortimport.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| pkg/cli/health_command.go | Replaces bubble sort with slices.SortFunc for success-rate ordering. |
| pkg/cli/compile_config.go | Uses sliceutil.Map and a pure sanitizer helper to produce sanitized validation output. |
| pkg/cli/logs_report.go | Replaces index-based sorting with type-safe slices sorting and cmp.Compare. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
This was referenced Mar 10, 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.
Functional and immutability improvements to the
pkg/clipackage. This is run 1 of a systematic round-robin series covering all packages.Next package to process:
pkg/consoleSummary
Three files updated with tasteful functional improvements:
health_command.goslices.SortFunccompile_config.gosliceutil.Map+ pure helperlogs_report.gosort.Slice/sort.Strings→slices.SortFunc/slices.SortsortimportNet: 38 insertions, 53 deletions (net −15 lines)
1. Replace Bubble Sort with
slices.SortFunc(health_command.go)Before — O(n²) bubble sort with a comment apologizing for it:
After — O(n log n), expressive, uses the standard
slicespackage:2. Declarative Sanitization with
sliceutil.Map(compile_config.go)Before — nested imperative loops with index tracking:
After — extracted pure helper + declarative nested
Map:3. Type-safe Sorting with
slices.SortFunc(logs_report.go)Replaced 6
sort.Slice+ 3sort.Stringscalls with their type-safe equivalents from theslicespackage. Thesortpackage import is removed entirely.Benefits:
(a, b T)instead of index-basedresult[i]/result[j]cmp.Compareeliminates hand-written comparison logicslices.Sortreplacessort.Stringsconsistentlyslices.Containsalready in the filePrinciples Applied
sanitizeErroris a pure function — same input always gives same output, no side effects, easily testable in isolationsliceutil.Mapexpresses what to transform, not how to iterateslicespackage (Go 1.21+) oversortpackage for type-safe slice operationsTesting
TestHealthConfigValidation,TestHealthCommand,TestCalculateWorkflowHealth,TestGroupRunsByWorkflow,TestCalculateHealthSummary— all passTestBuildMCPToolUsageSummarySorting— passes (validates sort order maintained)go build ./pkg/cli/— cleango vet ./pkg/cli/— cleanmake fmt— no changes needed