Repository navigation
refactor(tui): UI-neutral input seam, crossterm as an adapter - #551
Merged
Merged
Conversation
App::on_input(Input) holds the key logic with no terminal types; term_input maps crossterm key events to Input (releases dropped, unmapped keys become Key::Other so they still disarm Ctrl+C). on_key remains the terminal entry point, so every existing test passes unchanged.
🔍 Cora AI Code Review✅ No issues found. Code looks good! Review powered by cora-code · BYOK · MIT |
3 of 4 tasks
ajianaz
added a commit
that referenced
this pull request
Nov 10, 2026
## What Second part of #526 (UI epic #523): `TuiHost` shrinks from eleven methods to three (`footer`, `run_turn`, `apply`). `apply(HostCmd) -> Result<HostReply, String>` replaces `models`, `set_model`, `set_effort`, `request_compaction`, `new_session`, `sessions`, `switch_session`, `status_lines` and `set_name`. Refs #526, does not close it. ## Why Eight of the eleven methods defaulted to `unsupported()` and duplicated the `HostCmd` enum, and the trait had one adapter, so a second UI (GPUI, a remote client) had a wide interface to implement for what is really "apply this command". With one call, a remote adapter writes three methods. Agreed as part of the #526 plan (the issue's item 3); the input seam (#551) was part 1. ## Changes - `tole-tui`: - `HostReply { Done, Session(id), Models, Sessions, Lines }`: data only. The wording shown to the user ("model → x", "new session s-9", "(failed: ...)") and the pickers stay in the UI (`run_host_cmd`), so a host has no UI text to produce. - `TuiHost::apply` default: supports `Status` (no lines) and refuses the rest with "not supported by this host", exactly what the removed defaults did. - `run_host_cmd` decides what to say before handing the command over, then maps the reply. A reply of the wrong kind (e.g. a model list for a model change) is reported in the transcript as `(failed: unexpected host reply ...)`, never a panic. - `tole-cli` `TuiSession`: `footer` and `run_turn` stay in the trait impl; the nine operations become plain inherent methods (same bodies, same errors), and `apply` dispatches to them. Its existing unit tests call those methods and are unchanged. - No slash command is lost; user-visible behavior is unchanged. - CHANGELOG (Changed), `docs/tui.md` (Architecture: host seam) and `docs/epics.md` updated in the same PR (AGENTS.md §7); README unaffected. - **Breaking for anyone implementing `TuiHost` outside this repository** (override `apply` instead of the removed methods); new public item `tole_tui::HostReply`. Called out in the CHANGELOG. ## Testing - [x] `cargo fmt --all -- --check`, `cargo clippy --workspace --all-targets -- -D warnings`, `cargo check -p tole-cli --no-default-features`, `cargo test --workspace` (1203 passed: the previous 1195 plus 8). The 63 existing `tole-tui` tests, including the loop-level footer-refresh test (its host now overrides `apply`), and the real-terminal `tui_e2e` suite pass. - [ ] Local `cora review --staged`: not run (cora is not installed in this environment); the CI Cora Review job is the verdict. - [x] The acceptance item "a fake host in tests exercises the same interface a remote adapter will use": `FakeHost` has only the three methods, records every command and answers with scripted replies. 7 new `tole-tui` tests: each change is exactly one `apply` call with the UI's wording and a stale footer; New/Switch report the session id the host names; model and session pickers open from the host's data, and empty or failed ones say so; status lines are shown as given; a failing host is reported and leaves the footer alone; a wrong-kind reply is reported; a host that implements nothing supports `Status` and refuses the rest. - [x] 1 new `tole-cli` test: `TuiSession::apply` dispatches every command to its session operation (what each wrote, read back through the session's own readers; bad input refused with the operation's own error; `New`/`Switch` answer with the session now in use; `Status` lines; `PickSession` without an index). - Mutations, each caught: New/Switch wording swapped, the footer never marked stale (3 tests), the adapter's `Compact` doing nothing, and `Name` routed to the wrong operation. ## Unrelated flake seen while testing One full-workspace run failed `tole-core` `turn_loop::turn_survives_reopen_between_steps` with `Locked { holder: <our own pid> }`; it passed on the next full run (1203). It is the same signature as an earlier flake, and I reproduced the cause with a throwaway probe (207 of 3000 reopens fail while other threads spawn child processes, 0 of 3000 without) and filed it as #552 with the evidence and a proposed fix. Not part of this PR. ## Next in #526 Part 3: model a pending approval as source-agnostic UI state that carries its risk tier (a UI never offers allow-always for `Destructive`; today the in-process `Prompter`, remotely the `/approvals` queue). ## Related Issues Refs #526, part of #523. Related: #464, #463, #552. --- _Generated by [Claude Code](https://claude.ai/code/session_01GwJr9GzLbDFeXo3HZHZpyP)_ Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
First part of #526 (UI epic #523): the TUI's key logic takes a UI-neutral
Inputinstead of a crosstermKeyEvent.App::on_input(Input)holds the logic; a crossterm adapter maps key events onto it. Refs #526, does not close it.Why
A second UI (the GPUI desktop, #527) can only reuse
tole-tui's state machine if that logic is not welded to the terminal.App::on_keytook a crosstermKeyEventand mixed key decoding with state. The issue's plan is to do this insidetole-tui(no new crate until a second consumer exists), in small behavior-preserving steps; this is the input one, the biggest of the three.Changes
input.rs(new, no terminal types):Key::{Char, Enter, Esc, Tab, BackTab, Backspace, Up, Down, Other},Mods { ctrl, alt, shift },Input { key, mods }with small constructors. These are exactly the keys the logic distinguishes today;docs/tui.md's key table stays the behavior contract.term_input.rs(new, crossterm adapter):input_from(KeyEvent) -> Option<Input>(a key release is dropped, as before) andApp::on_key(KeyEvent), kept as the terminal entry point.lib.rs:on_keybecomeson_input;picker_keyandanswertake aKey. The key-matching logic is unchanged apart from the types. The crossterm key imports are gone from the production code (the event loop keeps its terminal imports;App's input path has none).Key::Otheris deliberate: every key the logic does not distinguish (Left, Home, F5, ...) still counts as "a key was pressed", so it still disarms a pending Ctrl+C and re-asks an approval, exactly as before. Mapping them toNonewould have silently changed Ctrl+C, Left, Ctrl+C from "arms twice" to "quits".docs/tui.md(Architecture: the input seam), CHANGELOG (Changed; new public itemstole_tui::{Input, Key, Mods}) anddocs/epics.mdupdated in the same PR (AGENTS.md §7); README unaffected.Testing
cargo fmt --all -- --check,cargo clippy --workspace --all-targets -- -D warnings,cargo check -p tole-cli --no-default-features,cargo test --workspace(1195 passed: the previous 1187 plus 8). The 55 existingtole-tuitests pass unchanged (they driveon_keythrough the adapter), and the real-terminaltui_e2esuite (a pty against a scripted provider) passes.cora review --staged: not run (cora is not installed in this environment); the CI Cora Review job is the verdict.Key::Other(not dropped), drops a release and acts on a repeat, and a release does not disarm Ctrl+C; andAppdriven withInputs alone (no crossterm): type and submit, Shift/Alt/Ctrl+J newlines versus plain Enter, an ignored key still disarming Ctrl+C, and BackTab being its own key.Other(adapter test), the Enter-newline ruleshift || altturned into&&(four tests, including a new one), and the adapter reading Ctrl from the Alt flag (caught as a hang of an existing scripted event-loop test that never reaches its quit key, which the timeout reported as a failure, not as a clean assertion).Next in #526
Part 2: collapse the per-command
TuiHostmethods into oneapply(HostCmd)path plusrun_turn,footerandsessions, with a fake host in tests for the interface a remote adapter will implement. Part 3: model a pending approval as source-agnostic UI state that carries its risk tier (a UI never offers allow-always forDestructive).Related Issues
Refs #526, part of #523. Related: #464, #463.
Generated by Claude Code