# src/tui/controller KNOWLEDGE BASE
## OVERVIEW
Main event loop, event drain, input dispatch, worker lifecycle, and side-effectful TUI actions. Owns `MissionControlApp`: mutable runtime boundary between input state and display state.
## STRUCTURE
```text
src/tui/controller/
├── mod.rs # module boundary, re-exports
├── app_support.rs # picker sizing, browser open, activity namespace
├── drain.rs # DrainResult and event application
├── pacing.rs # RedrawIntent, cursor blink, timer math, mouse scroll coalescing
└── app/ # MissionControlApp struct + split impl blocks
├── mod.rs # struct def, run() main loop, paste-burst heuristic
├── auth.rs # login/logout flows, custom provider setup
├── catalog.rs # model picker and model selection
├── compaction.rs # /compact session compaction worker
├── modals.rs # skills/sessions/thinking/primary-agent pickers
├── submit.rs # prompt submit, slash commands, steering queue, worker spawn
└── workers.rs # worker join, cancel, reconcile, timeout
```
## WHERE TO LOOK
| Main loop | `app/mod.rs::run()` | Event select, drain, draw, input dispatch, timer. |
| Submit/commands | `app/submit.rs` | Slash commands, prompt submission, worker thread spawn. |
| Worker lifecycle | `app/workers.rs` | Join, cancel, reconcile outcome, timeout detach. |
| Auth flows | `app/auth.rs` | Login/logout, OAuth callback, custom provider wizard. |
| Event drain | `drain.rs` | `drain_tui_events`, output/activity/control application. |
| Redraw control | `pacing.rs` | `RedrawIntent`, blink/timer, mouse scroll batching. |
## CONVENTIONS
- Worker spawn is fire-and-forget; completion detected via `handle.is_finished()` poll in main loop.
- Cancellation sets `AtomicBool`; worker checks before provider call and during streaming.
- Steering feedback syncs from pending count changes.
## ANTI-PATTERNS
- Do not mutate `MissionControlState` directly from input handlers; route through controller actions.
- Do not block main loop on worker joins; use timeout detach.
- Do not spawn provider work outside `WorkerState` tracking.
- Do not bypass `DrainResult` for event-application state changes.
- Do not let paste-burst heuristic fire during active modals.
- Do not coalesce mouse scroll across different panes.