Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/dim-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,10 @@ answer text (including its retained streaming tail)

Both TUI modes share the same composer border layout: the adopted model and, when its configuration carries one, the reasoning effort it sends (`provider / model · effort`) sit at the right of the top border, while shell mode keeps the top-border left title. The bottom border keeps the run status, status slot (a notice, `esc interrupt`, `permission required` / `answer required`, disconnect), background task count, goal and main branch context reading (`1.8K / 256K`) at the left, and the attached Session's workspace, git branch and unread badge at the right, with Home naming the launch directory. The permission preset is not in that border: both modes show only the live permission footer described above, without an `AGENT` prefix, with its hint in the selected interface language. While a prompt replaces the composer, a notice or the disconnect state is drawn once, on the rows above the footer. Scrollback keeps its `›` prompt, while fullscreen omits the prompt mark and keeps mouse targets such as clicking the model label. The live footer is not committed to transcript history. When the workspace differs from the CLI's `--cwd`, the `@` picker names the `--cwd` in its title, so local file completion still says which directory it lists. A box too narrow for the whole model label drops the effort first, then the label.

In scrollback, left-click a text cell to move the insertion point while editing a nonempty draft with mouse mode on. If the draft has scrolled to a different first row, the first click acknowledges the new view without moving the cursor. Click again to place it. This prevents a delayed click on the previous view from editing the wrong row.

Clearing or submitting the draft, opening a picker or prompt, or turning mouse mode off returns mouse handling to the terminal. While Dim receives mouse reports, native selection and wheel scrolling depend on the terminal's mouse override gesture. If you use the terminal's scrollbar or a scrollback key binding, return to the live view before clicking the draft: Dim cannot see the terminal's history offset.

The Git branch label follows branch switches in both modes, including switches made by tools or another terminal. At startup the client resolves the workspace's own Git `HEAD` path (including linked worktrees); the existing UI timer reads that file at most once every 10 seconds, without spawning more Git processes, and requests a repaint only when the name changes. Detached HEAD displays `HEAD`; a transient read failure keeps the last known name until the next check.

If no Git branch is available at startup, the composer shows only the working directory, without parentheses or a placeholder. The welcome banner still reports `Not available` for its Git branch field. Initializing a repository later requires restarting the TUI to discover it. The client does not repeatedly spawn Git to look for a new repository.
Expand Down Expand Up @@ -1236,7 +1240,7 @@ Opening `/` selects `/new`; pressing Enter starts a new session. `/permissions`

Typing ranks the matches: the exact name, a name prefix, an alias prefix, a prefix of a name part (`reload-skills` for `sk`), a name containing the query, a description word starting with it, then three or more letters in order through the name (`stg` for `settings`); a match inside a description word does not count. Equally ranked matches keep the fixed order.

`/settings` gathers the interface settings: theme and language (each opens its picker and comes back), the startup form (`tuiMode`), the default send mode (`tuiDefaultSendMode`), tool details (`tuiToolDetails`: `collapsed`, `summary`, `expanded`), thinking details (`tuiThinkingDetailsExpanded`), the fullscreen mouse (`tuiMouseMode`: off hands selection and the wheel to the terminal), notifications (`tuiNotifyOnComplete`, on by default), ACP Sessions in `/resume` (`showAcpSessions`, off by default), the permission preset and execution settings. Tool and thinking details are independent and both default to collapsed in both modes. The old `tuiToolDetailsExpanded` boolean is read when no valid three-state preference exists; new changes save to `tuiToolDetails` without replacing the legacy key's format. In scrollback, collapsed tool groups retain their header and member cards; summary shows one row per call; expanded shows full details. In fullscreen these are defaults for independent nodes: collapsed closes batches, summary opens containers with call details closed, and expanded opens both; explicit per-node choices take precedence. Edit and Write details show recorded old/new unified comparisons, including new-file additions; records without a diff explicitly say comparison is unavailable. Compaction bodies show only in expanded, and so does a hook's context (below). `/tools` cycles the defaults without changing thinking or clearing fullscreen manual choices. Model selection stays in `/model` (`/models`). Settings change with `Enter`, `←`/`→` or `Space` and save to `config.json` at once. See the [transcript detail settings contract](../../docs/design/cli-commands.md#transcript-detail-settings).
`/settings` gathers the interface settings: theme and language (each opens its picker and comes back), the startup form (`tuiMode`), the default send mode (`tuiDefaultSendMode`), tool details (`tuiToolDetails`: `collapsed`, `summary`, `expanded`), thinking details (`tuiThinkingDetailsExpanded`), mouse input (`tuiMouseMode`: off hands selection and the wheel to the terminal), notifications (`tuiNotifyOnComplete`, on by default), ACP Sessions in `/resume` (`showAcpSessions`, off by default), the permission preset and execution settings. Tool and thinking details are independent and both default to collapsed in both modes. The old `tuiToolDetailsExpanded` boolean is read when no valid three-state preference exists; new changes save to `tuiToolDetails` without replacing the legacy key's format. In scrollback, collapsed tool groups retain their header and member cards; summary shows one row per call; expanded shows full details. In fullscreen these are defaults for independent nodes: collapsed closes batches, summary opens containers with call details closed, and expanded opens both; explicit per-node choices take precedence. Edit and Write details show recorded old/new unified comparisons, including new-file additions; records without a diff explicitly say comparison is unavailable. Compaction bodies show only in expanded, and so does a hook's context (below). `/tools` cycles the defaults without changing thinking or clearing fullscreen manual choices. Model selection stays in `/model` (`/models`). Settings change with `Enter`, `←`/`→` or `Space` and save to `config.json` at once. See the [transcript detail settings contract](../../docs/design/cli-commands.md#transcript-detail-settings).

Notifications reach a user who switched windows when the run finishes or waits on a permission or a question (each request once): iTerm2 gets `OSC 9`, kitty `OSC 99`, Ghostty, WezTerm and foot `OSC 777`; any other terminal gets a bell, which it turns into a Dock bounce, a taskbar flash or a tab badge. Inside a multiplexer the bytes differ, because neither carries the form upward by itself and a notification asserts nothing after it is delivered, so the record's reasons for staying inside a multiplexer (`ui::status`, `ui::progress`) do not apply to it. tmux gets the form in its passthrough wrapper (`ESC P tmux;`, the sequence's `ESC`s doubled, `ESC \`) followed by a bare `BEL`: tmux 3.3 and later default `allow-passthrough` to off, so a tmux that forwards the wrapper draws the notification and one that drops it still rings. GNU screen follows the same rule for the same reason: it doubles no `ESC` (`ESC P` opens a passthrough it ends differently from tmux, which a notification does not need), and some builds forward an `OSC` closed by `BEL` while others drop every `OSC` a pane writes — so a `BEL`-terminated form (`OSC 9`, `OSC 777`) goes through unwrapped as it is and a bare `BEL` follows it, which draws the notification where the form is forwarded and rings where it is dropped. kitty's `ST`-terminated `OSC 99` has no shape screen carries whole, so it becomes the bell alone. herdr gets a bell whatever its `TERM_PROGRAM` says: it reads a pane's `OSC`s for itself and notifies from its own list of terminals, so a form the pane's variables name is not known to reach the user, while a `BEL` is not an `OSC` it takes.

Expand Down
5 changes: 5 additions & 0 deletions crates/dim-cli/src/ui/composer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,11 @@ impl Composer {
}
}

/// Wrapped row at the top of the rendered textarea.
pub fn rendered_scroll(&self) -> u16 {
self.state.scroll
}

/// Place the cursor at `cell` and clear the selection. Both `cell` and the
/// rendered textarea `area` use screen columns and rows counted from the
/// top of the unclipped dock. Clicks outside `area` are ignored.
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/src/ui/i18n/de/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ pub fn lookup(english: &str) -> Option<&'static str> {
"Thinking details" => "Denkdetails",
"expanded" => "ausgeklappt",
"collapsed" => "eingeklappt",
"Mouse (fullscreen)" => "Maus (Vollbild)",
"Mouse" => "Maus",
"Permissions" => "Berechtigungen",
"Tool approvals" => "Tool-Freigaben",
"Execution" => "Ausführung",
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/src/ui/i18n/es/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ pub fn lookup(english: &str) -> Option<&'static str> {
"Thinking details" => "Detalles de razonamiento",
"expanded" => "expandido",
"collapsed" => "contraído",
"Mouse (fullscreen)" => "Ratón (pantalla completa)",
"Mouse" => "Ratón",
"Permissions" => "Permisos",
"Tool approvals" => "Aprobaciones",
"Execution" => "Ejecución",
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/src/ui/i18n/fr/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ pub fn lookup(english: &str) -> Option<&'static str> {
"Thinking details" => "Détails de réflexion",
"expanded" => "dépliés",
"collapsed" => "repliés",
"Mouse (fullscreen)" => "Souris (plein écran)",
"Mouse" => "Souris",
"Permissions" => "Autorisations",
"Tool approvals" => "Approbations d'outils",
"Execution" => "Exécution",
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/src/ui/i18n/id/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ pub fn lookup(english: &str) -> Option<&'static str> {
"Thinking details" => "Detail pemikiran",
"expanded" => "terbuka",
"collapsed" => "terlipat",
"Mouse (fullscreen)" => "Mouse (layar penuh)",
"Mouse" => "Mouse",
"Permissions" => "Izin",
"Tool approvals" => "Persetujuan tool",
"Execution" => "Eksekusi",
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/src/ui/i18n/ja/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ pub fn lookup(english: &str) -> Option<&'static str> {
"Thinking details" => "思考詳細",
"expanded" => "展開",
"collapsed" => "折りたたみ",
"Mouse (fullscreen)" => "マウス(全画面)",
"Mouse" => "マウス",
"Permissions" => "権限",
"Tool approvals" => "ツール承認",
"Execution" => "実行",
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/src/ui/i18n/ko/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ pub fn lookup(english: &str) -> Option<&'static str> {
"Thinking details" => "생각 상세",
"expanded" => "펼침",
"collapsed" => "접힘",
"Mouse (fullscreen)" => "마우스 (전체 화면)",
"Mouse" => "마우스",
"Permissions" => "권한",
"Tool approvals" => "도구 승인",
"Execution" => "실행",
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/src/ui/i18n/pt_br/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ pub fn lookup(english: &str) -> Option<&'static str> {
"Thinking details" => "Detalhes de raciocínio",
"expanded" => "expandido",
"collapsed" => "recolhido",
"Mouse (fullscreen)" => "Mouse (tela cheia)",
"Mouse" => "Mouse",
"Permissions" => "Permissões",
"Tool approvals" => "Aprovações de ferramentas",
"Execution" => "Execução",
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/src/ui/i18n/pt_pt/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ pub fn lookup(english: &str) -> Option<&'static str> {
"Thinking details" => "Detalhes de raciocínio",
"expanded" => "expandido",
"collapsed" => "recolhido",
"Mouse (fullscreen)" => "Rato (ecrã inteiro)",
"Mouse" => "Rato",
"Permissions" => "Permissões",
"Tool approvals" => "Aprovações de ferramentas",
"Execution" => "Execução",
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/src/ui/i18n/zh_cn/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ pub fn lookup(english: &str) -> Option<&'static str> {
"Thinking details" => "思考详情",
"expanded" => "展开",
"collapsed" => "折叠",
"Mouse (fullscreen)" => "鼠标(全屏)",
"Mouse" => "鼠标",
"Permissions" => "权限",
"Tool approvals" => "工具审批",
"Execution" => "执行",
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/src/ui/i18n/zh_hant/chrome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ pub fn lookup(english: &str) -> Option<&'static str> {
"Thinking details" => "思考詳情",
"expanded" => "展開",
"collapsed" => "收合",
"Mouse (fullscreen)" => "滑鼠(全螢幕)",
"Mouse" => "滑鼠",
"Permissions" => "權限",
"Tool approvals" => "工具核准",
"Execution" => "執行",
Expand Down
39 changes: 37 additions & 2 deletions crates/dim-cli/src/ui/render/screen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use std::borrow::Cow;
use std::io::{self, Write};

use ratatui::layout::{Rect, Size};
use ratatui::layout::{Position, Rect, Size};
use xai_ratatui_inline::{TerminalLike, emit_to_scrollback};

/// History rows kept visible when space permits.
Expand Down Expand Up @@ -43,7 +43,7 @@ pub struct Frame {
pub thought_rows: Vec<(usize, std::ops::Range<usize>, String, bool)>,
/// Model label row and columns in `live`, for the fullscreen model picker.
pub model_label: Option<(usize, std::ops::Range<usize>)>,
/// Editable text cells relative to the start of the fullscreen dock.
/// Editable text cells relative to the start of the dock.
pub composer: Option<Rect>,
/// Cursor position inside the live region (row, column), `None` hides it.
pub cursor: Option<(u16, u16)>,
Expand Down Expand Up @@ -100,6 +100,7 @@ pub struct Screen {
cursor_visible: bool,
/// Where the terminal's cursor is after our last write, when known.
cursor_at: Option<(u16, u16)>,
composer: Option<(Rect, usize)>,
synchronized: bool,
}

Expand All @@ -118,6 +119,7 @@ impl Screen {
painted: Vec::new(),
cursor_visible: true,
cursor_at: None,
composer: None,
synchronized,
}
}
Expand All @@ -126,6 +128,17 @@ impl Screen {
self.size
}

/// Maps a screen cell to the rendered composer box and cell, keeping screen columns
/// and using dock-relative rows. Cells outside the visible editor return `None`.
pub fn composer_hit(&self, x: u16, y: u16) -> Option<(Rect, Position)> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

P3. This new mapping has no contract comment and no focused test.

Problem: x is a screen column while the returned row is relative to the dock, and the result depends on self.top, self.viewport_height and the blank rows layout inserts above the dock (screen.rs:161-184). The committed scenario covers one 60-column wrapped row with a wide character (scripts/tui-tmux/scenarios.mjs:536-563); it does not cover a padded dock or a viewport that cuts the live region, and the tmux suite is local-only.

Failure: a later change to the padding or clipping arithmetic shifts clicks by the padding rows while every CI check stays green; clicks then place the draft cursor on the wrong wrapped line.

Fix: add a /// contract note (screen columns, dock-relative rows, None outside the rendered box) and a unit test here for a cut tail and a shrinking-tail padded frame. I wrote such a probe locally and it passes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Fixed: composer_hit has the contract comment at crates/dim-cli/src/ui/render/screen.rs:131-133 and the focused test at crates/dim-cli/src/ui/render/screen.rs:906-924. The test covers a 14-row live region clipped by a 12-row screen, the padding layout inserts for a shrinking tail, the mixed screen-column and dock-row space, and cells outside the box on the left and top edges, so it would catch a screen-row mapping or a box that ignores its area. One optional gap remains: the assertions still pass if the dock offset or self.top is dropped, so the arithmetic is not fully pinned; the details and the fix are in an inline comment on screen.rs:919. The two P2 findings from the round 1 review are fixed as described in the review body.

let (area, dock_rows) = self.composer?;
let row = y.checked_sub(self.top)?;
let from_bottom = self.viewport_height.checked_sub(row)?;
let dock_row = dock_rows.checked_sub(usize::from(from_bottom))?;
let cell = Position::new(x, u16::try_from(dock_row).ok()?);
area.contains(cell).then_some((area, cell))
}

/// Where the shell left the cursor: the region starts there instead of
/// at the bottom of the screen.
pub fn set_origin(&mut self, row: u16) {
Expand Down Expand Up @@ -176,6 +189,9 @@ impl Screen {
/// (empty when nothing changed).
pub fn render(&mut self, frame: &Frame, size: (u16, u16)) -> Vec<u8> {
let mut out = Vec::new();
self.composer = frame
.composer
.map(|area| (area, frame.live.len() - frame.dock));
let resized = size != self.size;
let (mut layout, mut wanted) = self.layout(frame, size);
let tail = visible_tail(&layout, wanted);
Expand Down Expand Up @@ -887,6 +903,25 @@ mod tests {
)
}

#[test]
fn composer_click_tracks_the_visible_box_in_clipped_and_padded_frames() {
let (mut screen, mut emu) = setup(true);
screen.set_origin(0);
for tail in [10, 1] {
let mut rows = vec!["tail"; tail];
rows.extend(["border", "first", "second", "status"]);
let mut f = docked(&rows, tail, None);
let area = Rect::new(3, 1, 8, 2);
f.composer = Some(area);
drive(&mut screen, &mut emu, &f);
let drawn = emu.rows_text();
let y = drawn.iter().position(|row| row == "second").unwrap() as u16;
assert_eq!(screen.composer_hit(5, y), Some((area, Position::new(5, 2))));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[P3] This test passes for two wrong mappings, so it does not fully pin the arithmetic it was added for. I changed dock_row to usize::from(from_bottom) (dropping the dock_rows offset) and the test still passed because the only positive click is on second, whose dock row equals its from-bottom distance in both frames. I also changed row to y (dropping self.top) and it still passed because set_origin(0) keeps self.top at 0. Failure: with either change, a click on the composer border or status row at the bottom of the viewport is accepted as the first text row, or every click shifts by the shell origin, while CI stays green. Fix: also assert a click on the first row (correct cell 1; from-bottom-only 3, outside the two-row area) and render one frame with a non-zero origin. Both mutations are reverted.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Remains at ee8dcae: the new commit does not touch crates/dim-cli/src/ui/render/screen.rs. I re-applied both mutations at this head and the focused test at crates/dim-cli/src/ui/render/screen.rs:906-923 still passes each time. let dock_row = usize::from(from_bottom); drops the dock offset, and the positive click on second cannot distinguish it. let row = y; drops self.top, and set_origin(0) keeps both frames at 0. The new tmux scenario exercises the mapping end to end, but CI does not run that suite, so the unit gap stands. The fix from the original comment still applies: also click the first row (cell 1 under the correct mapping; 3 under the from-bottom-only formula, outside the two-row box) and render one frame with a non-zero origin. Both mutations are reverted. Optional at this round.

assert_eq!(screen.composer_hit(5, y - 2), None);
assert_eq!(screen.composer_hit(2, y), None);
}
}

#[test]
fn live_region_is_pinned_to_the_bottom_rows() {
let (mut screen, mut emu) = setup(true);
Expand Down
6 changes: 1 addition & 5 deletions crates/dim-cli/src/ui/settings_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,7 @@ impl SettingsPanel {
}
.to_owned(),
),
row(
Setting::Mouse,
"Mouse (fullscreen)",
on_off(values.mouse).to_owned(),
),
row(Setting::Mouse, "Mouse", on_off(values.mouse).to_owned()),
row(
Setting::Notify,
"Notify when agent needs you",
Expand Down
22 changes: 13 additions & 9 deletions crates/dim-cli/src/ui/terminal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ pub struct Terminal {
coalesce_min_run: Option<usize>,
queue: std::collections::VecDeque<InputEvent>,
keyboard: KeyboardProtocol,
mouse_requested: bool,
background_report: Option<String>,
clipboard: bool,
/// The terminal answered the program status query (`OSC 7501`): it keeps
Expand Down Expand Up @@ -246,6 +247,7 @@ impl Terminal {
),
queue: Default::default(),
keyboard: KeyboardProtocol::Legacy,
mouse_requested: false,
background_report: None,
clipboard: false,
program_status: false,
Expand Down Expand Up @@ -287,9 +289,9 @@ impl Terminal {
} else {
bytes.extend_from_slice(Mode::Mouse.restore_sequence());
bytes.extend_from_slice(Mode::AltScreen.restore_sequence());
modes::clear(Mode::Mouse);
modes::clear(Mode::AltScreen);
}
self.mouse_requested = on;
if self.keyboard == KeyboardProtocol::Kitty {
bytes.extend_from_slice(Mode::KittyKeyboard.enable_sequence());
}
Expand All @@ -314,22 +316,17 @@ impl Terminal {
self.writer.send(bar.to_vec())
}

/// Mouse reporting is on.
pub fn mouse(&self) -> bool {
modes::is_live(Mode::Mouse)
}

/// Turns mouse reporting on or off on the alternate screen; off hands
/// Turns mouse reporting on or off; off hands
/// selection and the wheel back to the terminal.
pub fn set_mouse(&mut self, on: bool) -> io::Result<()> {
if on == self.mouse() || !modes::is_live(Mode::AltScreen) {
if on == self.mouse_requested {
return Ok(());
}
self.mouse_requested = on;
if on {
modes::mark(Mode::Mouse);
self.writer.send(Mode::Mouse.enable_sequence().to_vec())
} else {
modes::clear(Mode::Mouse);
self.writer.send(Mode::Mouse.restore_sequence().to_vec())
}
}
Expand Down Expand Up @@ -419,6 +416,12 @@ impl Terminal {
self.writer.pending.load(Ordering::SeqCst) > 0
}

/// Drops mouse reports already read against a superseded scrollback frame.
pub fn discard_queued_mouse(&mut self) {
self.queue
.retain(|event| !matches!(event, InputEvent::Mouse(_)));
}

/// True once a background write failed (terminal gone).
pub fn write_failed(&self) -> bool {
self.writer.lost.load(Ordering::SeqCst)
Expand Down Expand Up @@ -597,6 +600,7 @@ impl Terminal {
sys::restore_terminal_once_until(deadline);
sys::remove_signal_guard();
modes::clear_all();
self.mouse_requested = false;
}

fn drain_until_da1(&mut self, deadline: Instant) {
Expand Down
2 changes: 1 addition & 1 deletion crates/dim-cli/src/ui/terminal/modes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl Mode {
}
}

/// The modes currently on, shared with signal handlers.
/// Modes that may still need restoring, including those with a queued reset.
static LIVE: AtomicU16 = AtomicU16::new(0);

pub fn mark(mode: Mode) {
Expand Down
Loading