Skip to content

Refactor TUI command groups into focused implementations#2851

Draft
aboimpinto wants to merge 101 commits into
Hmbown:mainfrom
aboimpinto:feat/command-strategy
Draft

Refactor TUI command groups into focused implementations#2851
aboimpinto wants to merge 101 commits into
Hmbown:mainfrom
aboimpinto:feat/command-strategy

Conversation

@aboimpinto

@aboimpinto aboimpinto commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary

This is the first part of the command-strategy refactor from #2791. The goal of this PR is to stop treating large command implementation files as shared code and put command behavior next to the command groups that own it.

This PR does not intentionally remove command features. It restructures the implementation surface, removes dead command plumbing, and deletes tests that only protected public methods that production code no longer called.

What changed

  • Reorganized command groups toward the focused folder shape:
    • <command>_command.rs for command registration/handler metadata
    • <command>_impl.rs for the command behavior
    • mod.rs for the command module wiring
  • Removed the commands::shared tree. It was not truly shared command code anymore; most modules were either command-specific implementation pipework, placeholders, or APIs that were only exercised by tests.
  • Moved real cross-module behavior out of commands into neutral TUI modules:
    • config_actions.rs for config value handling
    • config_persistence.rs for config persistence used by commands and UI code
    • model_routing.rs for model selection and auto-routing used outside command handlers
    • conversation_state.rs for conversation reset behavior used outside command handlers
    • share_export.rs for async share/export behavior used by UI and the /share command
  • Localized command behavior from the old shared group implementation files into the owning command folders for core, session, skills, project, memory, utility, config, and debug command groups.
  • Removed placeholder config handler modules and public functions that were only referenced by tests or by dead-code paths.
  • Kept command handlers as the command entry points. Non-command callers now use neutral modules instead of reaching into commands internals.

Why

The old structure made files look shared when they were not shared. That created a lot of accidental pipework: command handlers called command impl files, those impl files called commands/shared/*, and some UI code also reached into command modules directly. That made ownership hard to reason about and kept public methods alive only because tests referenced them.

This PR moves command-specific behavior back under the command groups and extracts the small amount of real cross-module behavior into neutral modules outside commands.

Scope

This PR covers the command-group restructuring work. The remaining user_commands refactor is intentionally left for the follow-up tracked in #2791.

Notes on tests and dead code

A large part of the cleanup was removing tests that were testing public methods no production path called anymore. Those methods were not command behavior; they were dead APIs kept alive by the test suite. This PR keeps tests around command-owned behavior and neutral module behavior, but does not preserve tests whose only value was protecting removed dead-code methods.

Validation

  • cargo fmt --package codewhale-tui
  • git diff --check
  • cargo check -p codewhale-tui --bins
  • cargo check -p codewhale-tui --tests

Refs #2791

Paulo Aboim Pinto

aboimpinto added 30 commits June 3, 2026 17:41
…ded (pausable/paused flags extend the cancel window)
… prevent 'Command resumed' event overriding cancel status
… sync in dispatch_user_message; direct flag clear in cancel path
… app.pausable is true (new pausable command after cancel)
…Paused / Request was Resumed / Request was Cancelled
…ds race where late engine status overwrites cancel/resume; add guard in Event::Status handler; update test to verify guard

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request modularizes the command system in crates/tui by organizing commands into logical groups under a registry-based architecture using Command and CommandGroup traits. It also introduces a pausable workflow feature with workspace rollback support via git stash, and refactors shell invocation handling. The review feedback identifies several instances where the unstable let_chains feature is used (in config_impl.rs, trust_impl.rs, user_commands.rs, shell_invocation.rs, and slash_menu.rs), and provides actionable suggestions to rewrite these using standard nested if let blocks or is_some_and to ensure compatibility with stable Rust compilers.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread crates/tui/src/commands/groups/config/config/config_impl.rs
Comment thread crates/tui/src/commands/groups/config/trust/trust_impl.rs
Comment thread crates/tui/src/commands/user_commands.rs
Comment thread crates/tui/src/shell_invocation.rs
Comment thread crates/tui/src/tui/slash_menu.rs
@aboimpinto

Copy link
Copy Markdown
Contributor Author

Reviewed the Gemini Code Assist note about let-chain usage.

No code change was made for that item because this repository declares rust-version = "1.88" in Cargo.toml, CI uses stable Rust, and let chains are valid for the configured MSRV. The pattern is also already used broadly across crates/tui/src, so rewriting only the examples listed in this review would be unrelated churn for this command-structure PR.

The local validation for this branch passed with:

  • cargo fmt --package codewhale-tui
  • git diff --check
  • cargo check -p codewhale-tui --bins
  • cargo check -p codewhale-tui --tests

Paulo Aboim Pinto

@aboimpinto

Copy link
Copy Markdown
Contributor Author

Follow-up after the first review/CI pass:

  • Kept PR Refactor TUI command groups into focused implementations #2851 as a draft.
  • Moved the task checklist out of the PR body; the checklist now lives only in Refactor command dispatch from monolithic match to modular strategy pattern #2791.
  • Reviewed the Gemini let_chains feedback. The cited syntax is compatible with the repository MSRV (rust-version = "1.88"), so I documented that and resolved the related review threads as answered.
  • Fixed the actual CI failures:
    • removed a stale doc comment that triggered clippy
    • added narrow module_inception allows for command folders intentionally named the same as their groups (config, memory, skills)
    • made the Windows-only shell_program_stem import conditional
    • fixed auto-route reasoning parsing so router output maps to Off, High, and Max as intended

Latest CI run is green across Lint, macOS, Windows, Ubuntu, mobile smoke, version drift, and GitGuardian.

Paulo Aboim Pinto

@Hmbown

Hmbown commented Jun 10, 2026

Copy link
Copy Markdown
Owner

@aboimpinto — checking in on this one now that Layer 3 (#2888) is merged. Confirming the plan we're operating on: this PR stays open as the reference/proof PR for the layered re-landing series (#2871#2878#2888 → Layer 4+), and we close it once the final layer lands — none of it merges directly.

One question: the pause/resume/cancel lifecycle work tangled into this branch looks separable from the command-group extraction. Would you be up for carving it out into its own layered PR (against codex/v0.9.0-stewardship, same pattern)? It deserves its own review rather than riding along here.

Layer 4 (group-owned command modules) is green-lit over on #2888. Thanks for the discipline on this series — it's the model we want for big refactors.

@Hmbown

Hmbown commented Jun 10, 2026

Copy link
Copy Markdown
Owner

/lgtm

@Hmbown

Hmbown commented Jun 12, 2026

Copy link
Copy Markdown
Owner

v0.8.59 release triage: deferring this PR out of the release-stabilization lane. It is not being rejected; it is just not required to unblock 0.8.59 now that the current release blockers have narrow fixes on codex/v0.8.59-release-ready. I am moving the target label to v0.8.60 so this does not keep the 0.8.59 queue hostage.

@Hmbown Hmbown added v0.8.60 Targeting v0.8.60 and removed v0.8.59 Targeting v0.8.59 labels Jun 12, 2026
@Hmbown Hmbown modified the milestones: v0.8.59, v0.8.63 Jun 12, 2026
@Hmbown Hmbown added v0.8.63 Targeting v0.8.63 and removed v0.8.60 Targeting v0.8.60 labels Jun 12, 2026
Hmbown added a commit that referenced this pull request Jun 12, 2026
Harvested from PR #2851 by @aboimpinto

Co-authored-by: Paulo Aboim Pinto <aboimpinto@gmail.com>

Co-authored-by: Hunter Bown <hmbown@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup Code cleanup, refactor, or maintenance work tui Terminal UI behavior, rendering, or interaction v0.8.63 Targeting v0.8.63

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants