chore: refactor interactive session to reduce line count#6274
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR successfully refactors the interactive function from 275 lines to 35 lines by extracting command handling logic into focused helper methods and introducing new types for better code organization.
Key Changes:
- Introduces
InputActionenum to control loop flow (Continue, Break, Proceed) - Adds
HistoryManagerstruct to encapsulate command history operations - Extracts 10 helper methods for specific command handling, improving code readability and maintainability
Split the interactive session function from 275 lines to 35 lines by extracting: - HistoryManager struct for command history loading/saving - InputAction enum for loop control flow - create_editor() for rustyline editor setup - handle_input() for dispatching input commands - handle_message_input() for processing user messages - handle_toggle_theme() and handle_select_theme() for theme commands - handle_goose_mode() for mode switching - handle_plan_mode() for plan mode entry - handle_clear() for clearing session - handle_recipe() for recipe generation - handle_compact() for conversation compaction This brings the function well under the 200 line target.
DOsinga
reviewed
Jan 5, 2026
| old_history_file: PathBuf, | ||
| } | ||
|
|
||
| impl HistoryManager { |
Collaborator
There was a problem hiding this comment.
FWIW we should just get rid of this and base it on the session manager I think and then extent it to the desktop (keeps its own history) too maybe?
DOsinga
approved these changes
Jan 5, 2026
zanesq
added a commit
that referenced
this pull request
Jan 6, 2026
* 'main' of github.com:block/goose: refactor: when changing provider/model,load existing provider/model (#6334) chore: refactor configure_extensions_dialog to reduce line count (#6277) chore: refactor handle_configure to reduce line count (#6276) chore: refactor interactive session to reduce line count (#6274) chore: refactor docx_tool to reduce function size (#6273) chore: refactor cli() function to reduce line count (#6272) make sure the models are using streaming properly (#6331) feat: add a max tokens env var (#6264) docs: slash commands topic (#6333) fix(ci): prevent gh-pages branch bloat (#6340) chore(deps): bump qs and body-parser in /documentation (#6338) Skip the smoke tests for dependabot PRs (#6337)
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.
Summary
Refactors the
interactivefunction incrates/goose-cli/src/session/mod.rsfrom 275 lines to 35 lines by extracting input handling, command processing, and UI rendering into separate helpers.Changes
New Types
InputActionenum: Controls main loop flow (Continue, Break, Proceed)HistoryManagerstruct: Encapsulates command history loading/saving logicExtracted Helper Methods
create_editor(): Sets up the rustyline editor with completionhandle_input(): Dispatches input commands to appropriate handlershandle_message_input(): Processes user messages in normal/plan modeshandle_toggle_theme()/handle_select_theme(): Theme switchinghandle_goose_mode(): Mode switching (auto, approve, chat, smart_approve)handle_plan_mode(): Plan mode entry and initial message processinghandle_clear(): Session clearinghandle_recipe(): Recipe generationhandle_compact(): Conversation compactionResult
The
interactivefunction is now 35 lines, well under the 200 line target.Testing