Skip to content

chore: refactor interactive session to reduce line count#6274

Merged
baxen merged 1 commit intomainfrom
baxen/TSK-704
Jan 6, 2026
Merged

chore: refactor interactive session to reduce line count#6274
baxen merged 1 commit intomainfrom
baxen/TSK-704

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree yeah

@baxen baxen merged commit d7a7b21 into main Jan 6, 2026
26 checks passed
@baxen baxen deleted the baxen/TSK-704 branch January 6, 2026 04:42
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)
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.

2 participants