Repository navigation
refactor: adopt modern Go stdlib helpers - #1566
Conversation
|
✅ OpenCodeReview: Review complete: 0 finding(s) across 25 selected item(s). |
Qiyuanqiii
left a comment
There was a problem hiding this comment.
I did another pass over the current head, this time also checking documentation impact, naming, comments, and the wording introduced by the refactor.
The stdlib substitutions still preserve the previous behavior: SplitSeq, maps.Copy, slices.Backward, the built-in min/max, range-over-int, and sync.WaitGroup.Go all match the control flow they replace here. The repository already targets Go 1.25.5, so these helpers do not raise the supported Go baseline.
I also don't see a documentation update that is required for this PR. It changes internal implementation only; CLI behavior, configuration, output formats, and user workflows stay the same.
The new and modified code comments are clear and describe the relevant invariants without over-explaining them.
No blocking findings from me. Approved.
ebc0b45 to
59d8c59
Compare
|
Heads up on the latest push: it's just a rebase onto current |
|
For some reason, the CI keeps failing tonight, even though GitHub claimed the issue has been fixed. |
59d8c59 to
df72e9a
Compare
|
Rebased onto current |
Replace hand-rolled loops with maps.Copy, slices.Contains(Func), min/max builtins, strings.SplitSeq/CutPrefix/CutSuffix, range-over-int and sync.WaitGroup.Go. No behavior change; adds a single-line fence case to the stripMarkdownFences tests.
df72e9a to
6efe7d6
Compare
|
Rebased onto current |
Description
Mechanical cleanup: hand-rolled loops are replaced with the standard-library helpers available at the module's
go 1.25baseline, and no-op type conversions are dropped. The behavior should not change.maps.Copyin place of copy-a-map loops (provider_tui.go,llm/client.go,llm/resolver.go,llmloop/loop.go,mcp/provider.go,tool/file_read_diff.go)minbuiltin in place ofif end > len(x) { end = len(x) }clamps (agent,scan/batch.go,llm/keycmd.go); the package-localmaxinsuggestdiffis dropped in favor of the builtinstrings.SplitSeq/bytes.SplitSeqwhere the split result is only iteratedstrings.CutPrefix/CutSuffixin place of pairedHasPrefix+TrimPrefixslices.Contains/slices.ContainsFuncin place of linear-search loopsinternal/llm:shared.ChatModel,openai.ResponsesModelandanthropic.Modelare plainstringaliases, andshared.FunctionParameters(...)is unnecessary because amap[string]anyis assignable to itsync.WaitGroup.Goin place ofAdd(1)+go func(){ defer Done() }(). IntriggerAsyncCompression,Gostill registers the job before the goroutine starts, so theWaitBackgroundinvariant noted in the comment still holds.In
stripMarkdownFences(both copies) only the suffix branch usesCutSuffix. The prefix branch is left as is on purpose: rewriting it withCutPrefixwould feed the"```"-only cut into the no-newline path and leavejsonbehind for input like```json{}```. A single-line fence case is added to both test tables to guard that path.Newer code. A third commit applies the same helpers to code added since this PR was opened, mostly
internal/behaviortask,internal/chatgptauthandinternal/gitcmd:strings.SplitSeq(17), range-over-int (17),sync.WaitGroup.Go(8),slices.Contains(3),maps.Copy(2),slices.Backward(1) andmin(1). They come fromgo fix's modernizers of the same kinds, run for linux, windows and darwin, with each non-trivial rewrite read by hand. Itsstringscutprefixproposal forstripMarkdownFencesis left out for the reason above, andomitzerois not applied because it would change JSON output.Type of Change
How Has This Been Tested?
make testpasses locallymake checkalso passes (license, english, gofmt, vet). The new single-line fence cases fail against theCutPrefixrewrite ofstripMarkdownFencesand pass with this change.go vetalso passes forGOOS=windows, and both modules build for windows and darwin on amd64 and arm64.TestPendingLoginConcurrentAccountOperations/return-logincan time out under heavy CPU load (it allows one second for a full second login); it does so onmainas well, and this change does not touch that path.Checklist
go fmt,go vet)AI disclosure: prepared with Claude Code (Claude Opus 5.5). It reviewed an IDE-suggested modernization diff, fixed a regression and a build break in it, and added the test cases. I reviewed every line.
Related Issues
None.
🤖 Generated with Claude Code