Skip to content

Use the slices package to simplify slice operations#2566

Merged
dgageot merged 2 commits intodocker:mainfrom
dgageot:board/refactor-codebase-to-use-slices-package-16f36c45
Apr 28, 2026
Merged

Use the slices package to simplify slice operations#2566
dgageot merged 2 commits intodocker:mainfrom
dgageot:board/refactor-codebase-to-use-slices-package-16f36c45

Conversation

@dgageot
Copy link
Copy Markdown
Member

@dgageot dgageot commented Apr 28, 2026

Replace manual loops and append-slice tricks with their slices/strings standard-library equivalents, and tidy a few small helpers along the way. Pure refactor — no behaviour change, all tests still pass.

slices package usage

File Before After
pkg/hooks/builtins/add_directory_listing.go sort.Strings(names) slices.Sort(names)
pkg/fsx/collect_test.go sort.Strings(got) slices.Sort(got)
pkg/tui/components/messages/messages.go append(s[:i], s[i+1:]...) (×2) slices.Delete(s, i, i+1)
pkg/tui/components/editor/editor.go append(e.attachments[:i], e.attachments[i+1:]...) slices.Delete(...)
pkg/tui/service/supervisor/supervisor.go manual index loops + append-delete + append-insert slices.Index / slices.Delete / slices.Insert
pkg/tui/dialog/working_dir_picker.go manual index loop in cycleSection slices.Index
pkg/config/hooks.go 12× append(append([]T{}, base...), cli...) 12× slices.Concat(base, cli)
pkg/hooks/handler.go append([]string{}, base...) slices.Clone(base)
pkg/runtime/runtime_test.go append([]tools.Tool{}, toolList...) slices.Clone(toolList)
pkg/session/migrations_unit_test.go append([]Migration{}, migrations...) slices.Clone(migrations)

Small tidy-ups

  • pkg/config/hooks.go: extracted defsFromCommands and matcherFromCommands helpers, collapsing five copy-pasted blocks in HooksFromCLI into a single struct literal.
  • pkg/hooks/handler.go: in hookEnv, replaced the manual for ... if ch == '=' scan with strings.Cut, and dropped the redundant index update on the append branch.
  • pkg/tui/service/supervisor/supervisor.go: removed the noop if runner.NeedsAttn { runner.NeedsAttn = false }, and dropped the unnecessary named return on CloseSession.

go build ./..., go vet ./..., golangci-lint run ./... (0 issues) and go test ./... all pass.

@dgageot dgageot requested a review from a team as a code owner April 28, 2026 09:20
@dgageot dgageot merged commit 0ed2ae9 into docker:main Apr 28, 2026
9 checks passed
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.

2 participants