refactor(tui): simplify components, drop dead code, consolidate helpers#2544
Merged
dgageot merged 2 commits intodocker:mainfrom Apr 27, 2026
Merged
Conversation
Remove unreachable functions, unused functional options and test-only helpers from the production code paths in pkg/tui. No behavior change; builds, lint, and the full test suite all pass. - scrollview: remove unused WithGapWidth option. - sidebar: remove unused WithLayoutConfig and Option type, drop the variadic opts ...Option from New (no caller passes any). - reasoningblock: remove the BlockMsg/blockMsgBase/ToggleMsg/ GetBlockID infrastructure; nothing constructed a ToggleMsg. - messages: drop the now-unreachable BlockMsg switch case in Update and the orphaned forwardToReasoningBlock helper. - tool/registry: collapse Register/RegisterAll into a single Register(registrations) entry point; the per-name overload was never called. - markdown: move newGlamourRenderer into fast_renderer_test.go (only tests used it); production renderer.go no longer needs the glamour or styles imports. - message: move stripANSI into message_test.go (only tests used it); production message.go no longer needs regexp. Assisted-By: docker-agent
Reduce boilerplate and surface area in pkg/tui/components/tool without changing behavior. Build, lint, and the full test suite still pass. - tool: collapse the Registry+Factory abstraction into a single package-level lookup table in factory.go and delete registry.go. The previous types (Registry, Factory, Registration, NewRegistry, NewFactory, the RWMutex) were never instantiated externally and added indirection for a static map. Resulting tool.New is the same API as before. - toolcommon: introduce NoArgsRenderer for tools that only need the "icon + name" header (user_prompt, todo_*). userprompt and todotool/component.go now collapse to a one-line New(). - toolcommon: add Pluralize helper and use it from listdirectory, directorytree, and searchfilescontent (each had its own copy/variant). The unit test moves to toolcommon alongside the helper. - toolcommon: drop the unused Base getters (Message, SessionState, Width, Height, Spinner). All renderers receive these directly via the Renderer signature. Assisted-By: docker-agent
gtardif
approved these changes
Apr 27, 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.
Two behavior-preserving refactor commits over
pkg/tui/components/. Build,go vet,golangci-lint run ./...(0 issues) and the fullgo test ./...suite all pass.Net diff: −277 / +103 across 17 files (one file deleted, two added).
Commits
1.
refactor(tui): drop dead code and unused options across componentsWithGapWidthoption.WithLayoutConfig, theOptiontype, and theopts ...Optionparameter onNew(no caller passes options).BlockMsg/blockMsgBase/ToggleMsg/GetBlockIDinfrastructure — no code ever constructs aToggleMsg, so the matching switch case inmessages.Updatewas unreachable.case reasoningblock.BlockMsg:branch and the orphanedforwardToReasoningBlockhelper.Registry.Register(name, builder)overload (onlyRegisterAllwas called).NewGlamourRendererintofast_renderer_test.goasnewGlamourRenderer(only tests use it). Productionrenderer.gono longer importsglamourorstyles.stripANSI(and its regex) intomessage_test.go. Productionmessage.gono longer importsregexp.2.
refactor(tui): simplify tool factory and consolidate render helpersRegistry+Factoryinto a single static lookup table infactory.go; deleteregistry.go. The previous abstraction (Registry,Factory,Registration,NewRegistry,NewFactory,sync.RWMutex) was never instantiated externally and added indirection over a static map.tool.NewAPI is unchanged. The map is initialized once at package load and only read afterwards, so the mutex is not needed.NoArgsRendererfor tools that only show the icon + tool name (e.g.user_prompt, todo helpers).userprompt.goandtodotool/component.gocollapse to a one-lineNew().Pluralize(count, singular, plural)and use it fromlistdirectory,directorytree, andsearchfilescontent(each had its own copy/variant). TheformatCountunit test moves totoolcommon/pluralize_test.goalongside the helper.Basegetters (Message,SessionState,Width,Height,Spinner) — every renderer already gets these via theRenderersignature.What was deliberately not touched
markdown/fast_renderer.go,messages/messages.go,editor/editor.go,editfile/render.go). Heavily exercised by tests; refactoring them is high-risk and orthogonal to readability.tab/tabbar(different concepts despite similar filenames; both used).scrollviewoptions (WithReserveScrollbarSpace,WithWheelStep,WithKeyMap) — all in active use.Renderer(msg, spinner, sessionState, width, height)signature, even where individual renderers ignore parameters, becauseBaseorchestrates spinners and resize uniformly.Validation
go build ./...✅go vet ./...✅golangci-lint run ./...✅ — 0 issuesgo test ./... -count=1✅ — all packages greendeadcode -filter pkg/tui/components/ ./...✅ — no remaining unreachable codeInternally reviewed (no bugs, security issues, concurrency issues, or coverage gaps found).