Skip to content

Conversation

@baxen
Copy link
Collaborator

@baxen baxen commented Dec 25, 2025

Summary

Refactors the interactive function in crates/goose-cli/src/session/mod.rs from 275 lines to 35 lines by extracting input handling, command processing, and UI rendering into separate helpers.

Changes

New Types

  • InputAction enum: Controls main loop flow (Continue, Break, Proceed)
  • HistoryManager struct: Encapsulates command history loading/saving logic

Extracted Helper Methods

  • create_editor(): Sets up the rustyline editor with completion
  • handle_input(): Dispatches input commands to appropriate handlers
  • handle_message_input(): Processes user messages in normal/plan modes
  • handle_toggle_theme() / handle_select_theme(): Theme switching
  • handle_goose_mode(): Mode switching (auto, approve, chat, smart_approve)
  • handle_plan_mode(): Plan mode entry and initial message processing
  • handle_clear(): Session clearing
  • handle_recipe(): Recipe generation
  • handle_compact(): Conversation compaction

Result

The interactive function is now 35 lines, well under the 200 line target.

Testing

  • All 112 tests pass
  • Clippy lint passes
  • Code formatted with cargo fmt

Copilot AI review requested due to automatic review settings December 25, 2025 03:13
Copy link
Contributor

Copilot AI left a 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 InputAction enum to control loop flow (Continue, Break, Proceed)
  • Adds HistoryManager struct to encapsulate command history operations
  • Extracts 10 helper methods for specific command handling, improving code readability and maintainability

@baxen baxen marked this pull request as draft December 25, 2025 03:29
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.
@baxen baxen marked this pull request as ready for review December 25, 2025 05:13
Copilot AI review requested due to automatic review settings December 25, 2025 05:13
Copy link
Contributor

Copilot AI left a 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.

@baxen baxen changed the title TSK-704: Refactor interactive session to reduce line count chore: refactor interactive session to reduce line count Dec 25, 2025
@baxen baxen mentioned this pull request Dec 26, 2025
11 tasks
old_history_file: PathBuf,
}

impl HistoryManager {
Copy link
Collaborator

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?

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.

3 participants