-
Notifications
You must be signed in to change notification settings - Fork 2.3k
chore: refactor interactive session to reduce line count #6274
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
| old_history_file: PathBuf, | ||
| } | ||
|
|
||
| impl HistoryManager { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
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