Uh oh!
There was an error while loading. Please reload this page.
[code-simplifier] refactor: simplify conditional server rows and redundant pattern splitting - #22306
Conversation
…tting - gateway_logs.go: eliminate duplicated if/else blocks for server rows and table config. Build the base row once and conditionally append the Filtered column; build headers similarly. Reduces ~20 lines of duplicate code while preserving identical behavior. - push_repo_memory.cjs: pre-compute patternStrs once before building the regex patterns array, removing two redundant re-splits of the fileGlobFilter string inside the map callback and the error block. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR refactors two recently modified areas to reduce duplication and improve clarity without changing behavior.
Changes:
- Simplifies
renderGatewayMetricsTableby building a single server row/header set and conditionally appending theFilteredcolumn. - Avoids redundant
FILE_GLOB_FILTERsplitting inpush_repo_memory.cjsby computingpatternStrsonce per scan.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/cli/gateway_logs.go | Deduplicates server-row and header construction in the gateway metrics table, conditionally adding the Filtered column. |
| actions/setup/js/push_repo_memory.cjs | Precomputes glob pattern strings once to avoid repeated trim/split/filter work during pattern validation/logging. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| row := []string{ | ||
| serverName, | ||
| strconv.Itoa(server.RequestCount), | ||
| strconv.Itoa(server.ToolCallCount), | ||
| fmt.Sprintf("%.0fms", avgTime), | ||
| strconv.Itoa(server.ErrorCount), | ||
| } | ||
| if hasFiltered { | ||
| serverRows = append(serverRows, []string{ | ||
| serverName, | ||
| strconv.Itoa(server.RequestCount), | ||
| strconv.Itoa(server.ToolCallCount), | ||
| fmt.Sprintf("%.0fms", avgTime), | ||
| strconv.Itoa(server.ErrorCount), | ||
| strconv.Itoa(server.FilteredCount), | ||
| }) | ||
| } else { | ||
| serverRows = append(serverRows, []string{ | ||
| serverName, | ||
| strconv.Itoa(server.RequestCount), | ||
| strconv.Itoa(server.ToolCallCount), | ||
| fmt.Sprintf("%.0fms", avgTime), | ||
| strconv.Itoa(server.ErrorCount), | ||
| }) | ||
| row = append(row, strconv.Itoa(server.FilteredCount)) | ||
| } | ||
| serverRows = append(serverRows, row) | ||
| } | ||
| headers := []string{"Server", "Requests", "Tool Calls", "Avg Time", "Errors"} | ||
| if hasFiltered { | ||
| output.WriteString(console.RenderTable(console.TableConfig{ | ||
| Title: "Server Usage", | ||
| Headers: []string{"Server", "Requests", "Tool Calls", "Avg Time", "Errors", "Filtered"}, | ||
| Rows: serverRows, | ||
| })) | ||
| } else { | ||
| output.WriteString(console.RenderTable(console.TableConfig{ | ||
| Title: "Server Usage", | ||
| Headers: []string{"Server", "Requests", "Tool Calls", "Avg Time", "Errors"}, | ||
| Rows: serverRows, | ||
| })) | ||
| headers = append(headers, "Filtered") | ||
| } |
There was a problem hiding this comment.
The refactor changes how the “Filtered” column and headers are constructed when metrics.TotalFiltered > 0, but there doesn’t appear to be a unit test that asserts the rendered table includes the Filtered header and the per-server filtered counts. Adding a test case with TotalFiltered > 0 (and a server with FilteredCount) would help prevent regressions in column alignment/output formatting.
Uh oh!
There was an error while loading. Please reload this page.
This PR simplifies recently modified code to improve clarity and reduce redundancy while preserving all functionality.
Files Simplified
pkg/cli/gateway_logs.go— Eliminated duplicated if/else blocks inrenderGatewayMetricsTableactions/setup/js/push_repo_memory.cjs— Removed redundantfileGlobFilterre-splittingImprovements Made
pkg/cli/gateway_logs.go— Server rows and table headers deduplicationThe
renderGatewayMetricsTablefunction contained two nearly-identicalif hasFilteredbranches — one to build server rows and one to configure table headers — resulting in ~20 lines of duplicated code. Simplified to build the base row once and conditionally append theFilteredcolumn:actions/setup/js/push_repo_memory.cjs— Pre-compute pattern stringsThe
scanDirectoryfunction calledfileGlobFilter.trim().split(/\s+/).filter(Boolean)three times:mapcallback to get each pattern string for debug loggingRefactored to compute
patternStrsonce before buildingpatterns, eliminating the redundant re-splits:Changes Based On
Recent changes from merged PRs (2026-03-22):
<b>for bold in details/summary and show#unknownentries with tool name (#22264) #22291 — fix(difc): use bold in details/summary and show#unknownentries with tool nameTesting
go test -count=1 -tags '!integration' ./pkg/cli/)gofmt)go build ./...)Review Focus
Please verify:
hasFilteredpush_repo_memorybehaves identically (same strings, same regexes)Automated by Code Simplifier Agent — analyzing code from 2026-03-22
Note
🔒 Integrity filter blocked 3 items
The following items were blocked because they don't meet the GitHub integrity level.
search_pull_requests: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".pull_request_read: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".pull_request_read: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".To allow these resources, lower
min-integrityin your GitHub frontmatter: