Skip to content

refactor(packages/app/src/components/prompt-input/build-request-parts.ts): split builders - #207

Open
Yumeseeker wants to merge 2 commits into
CMU-313:mainfrom
Yumeseeker:build-parts
Open

Yumeseeker wants to merge 2 commits into
CMU-313:mainfrom
Yumeseeker:build-parts

Conversation

@Yumeseeker

@Yumeseeker Yumeseeker commented Sep 14, 2026 •

Copy link
Copy Markdown

P1B: Starter Task: Refactoring PR

1. Issue

Link to the associated GitHub issue:
#206

Full path to the refactored file:
packages/app/src/components/prompt-input/build-request- parts.ts

What do you think this file does?
This file converts prompt attachments, context files, agent references, and images into request parts for the model. It also creates optimistic parts used to update the UI before the request completes.

What is the scope of your refactoring within that file?
I refactored buildRequestParts and extracted internal builders for file parts, agent parts, context and mention parts, and image parts.

Which Qlty‑reported issue did you address?
Function with many returns (count = 9): buildRequestParts, at line 91.

2. Refactoring

How did the specific issue you chose impact the codebase’s maintainability?
The function combined several unrelated responsibilities and contained many conditional return paths, making it harder to follow and safely modify. This increased the risk of accidentally changing ordering, deduplication, or path-handling behavior.

What changes did you make to resolve the issue?
I moved file, agent, context/comment, mention, and imageconstruction into focused internal helper functions. buildRequestParts now coordinates these builders and produces the final request and optimistic parts.

How do your changes improve maintainability? Did you consider alternatives?
Each helper now has one clear responsibility, while the main function reads as a straightforward assembly pipeline. I considered moving the logic into a separate module, but kept the helpers in the same file to avoid unnecessary abstraction.

3. Validation

How did you validate that the change is correct?
The focused test suite passes all 15 tests, including a new test covering file attachment source-text handling, and the refactored module has 100% function and line coverage. Targeted Qlty reports no remaining smells, changed-file lint reports 0 warnings and 0 errors, and the app typecheck passes.

screenshot of the test coverage showing the lines were executed by the tests.
image

screenshot showing the tests that cover the change passing during CI
image

screenshot of qlty smells --no-snippets packages/app/src/components/prompt-input/build-request-parts.ts showing fewer reported issues after the changes.
image

@Yumeseeker Yumeseeker changed the title Build parts refactor(app): split builders in packages/app/src/components/ prompt-input/build-request-parts.ts Sep 14, 2026
@Yumeseeker Yumeseeker changed the title refactor(app): split builders in packages/app/src/components/ prompt-input/build-request-parts.ts refactor(packages/app/src/components/prompt-input/build-request-parts.ts): split builders Sep 14, 2026
@Yumeseeker
Yumeseeker marked this pull request as ready for review September 14, 2026 22:38
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.

1 participant