Skip to content

refactor(tui): split 7.8k-line app.rs into cohesive app/ modules - #402

Closed
nhogenson wants to merge 1 commit into
Kuberwastaken:mainfrom
nhogenson:refactor/split-tui-app
Closed

refactor(tui): split 7.8k-line app.rs into cohesive app/ modules#402
nhogenson wants to merge 1 commit into
Kuberwastaken:mainfrom
nhogenson:refactor/split-tui-app

Conversation

@nhogenson

Copy link
Copy Markdown

Summary

tui/src/app.rs was a 7,807-line file containing the full App state struct, a 5,557-line impl block, the keyboard dispatch tree, and a 950-line test suite. This PR restructures it into app/ with one module per responsibility. Pure structural move — zero behavior change. Every function body is byte-identical to the original; no logic was touched, no warnings fixed, no style "improved" while moving.

Module layout

Module Responsibility Lines
mod.rs App struct, constructor, re-exports, module wiring ~940
types.rs Pure data model (messages, tool blocks, dialogs, state) 245
keys.rs Keyboard normalization + key-event dispatch 2,727
mouse.rs Pointer input, selection, context menu, paste viewer 660
providers.rs Provider/model/config + import-config flow 442
commands.rs Slash-command catalog + intercept dispatch 392
turns.rs Turn lifecycle (snapshots, streaming flush, labels) 176
messages.rs Transcript ops (add/replace/push, notifications, scroll) 162
prompt.rs Prompt input state machine + voice hold-to-talk 158
views.rs Overlay/dialog orchestration + MCP view state 405
run.rs Main event loop, query events, jump-to-error 628
tests.rs Test suite (moved whole, use super::*) 956

Public API unchanged — crate::app::{App, ...} re-exported from mod.rs exactly as before; zero ripples into render.rs, messages/, or lib.rs.

Visibility note (the one deliberate adjustment)

Private methods moved across module boundaries became pub(super) — restoring exactly the visibility the single-module layout provided. Of the 79 items lifted: 48 have genuine cross-module callers; 31 are used only within their defining file and are candidates to return to private during the phase-two interface work below.

Placement decisions

  • try_copy_to_clipboard stays in mod.rs — it's crate-level public API, re-exported by lib.rs (pub use app::try_copy_to_clipboard).
  • Animation/mode helpers (tick_rustle_pose, cycle_agent_mode, apply_theme, …) stay near the constructor for now; their callers live inside app, and regrouping them belongs with the interface work.
  • MCP plumbing in views.rs mirrors the original file's conflation; splitting it out is flagged for phase two.

Known follow-up (phase two, separate PRs)

Honest caveats this PR does not hide:

  • keys.rs remains the largest file — handle_key_event alone is ~2,300 lines and is the next target.
  • Submodule impl blocks still share the full App state; phase two replaces &mut self-everywhere with narrow interfaces and encapsulated state, and privatizes the ~31 lazy lifts.
  • cargo fmt stays advisory per repo policy — import ordering here matches the crate's existing conventions (messages/, etc.); fmt drift is at parity with upstream (156 diffs pre-split → 171 across the same volume).

Verification (matches CI gates)

  • cargo check --workspace --locked
  • cargo test --workspace --locked ✅ 1,799 tests, 0 failures (tui: 708)
  • cargo clippy --workspace --all-targets -D warnings ✅ clean
  • 208/208 functions preserved vs. original — 0 missing, 0 extra
  • Diff: app.rs deleted, 11 new files, +7,892 / −7,807 (the +85 is module glue)

No behavior change, no test changes, no dependency changes.

@nhogenson
nhogenson force-pushed the refactor/split-tui-app branch from c6486aa to 6410bbb Compare September 2, 2026 06:47
Pure structural move with zero behavior change: app.rs (7,807 lines)
becomes app/ with one module per responsibility — input (keys, mouse),
state model (types), provider management (providers), command dispatch
(commands), session lifecycle (turns, messages, run), and the test
suite (tests). Public API and re-exports are unchanged; the only
visibility adjustment is pub(super) on moved private methods, which
restores exactly the visibility the single-module layout provided.

Verified: workspace cargo check clean, full test suite green (~1,000
tests), and cargo clippy --workspace --all-targets -D warnings clean.
@nhogenson
nhogenson force-pushed the refactor/split-tui-app branch from 6410bbb to ff364a4 Compare September 2, 2026 06:49
@nhogenson

Copy link
Copy Markdown
Author

Closing per request — refile as SlugThugLabs when the org token is available.

@nhogenson nhogenson closed this Sep 2, 2026
@nhogenson
nhogenson deleted the refactor/split-tui-app branch September 2, 2026 07:01
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