From fa178cd7558a11966333559765e8d90be6edc801 Mon Sep 17 00:00:00 2001 From: zjywill Date: Fri, 20 Nov 2026 15:58:44 +0800 Subject: [PATCH 1/8] tui: draw scrollback composer borders with the fullscreen layout Scrollback put the run status on the composer's top border and the slot, context usage and model on the footer line. Both modes now use the fullscreen layout: status, slot and usage on the bottom border's left side, place and unread badge on its right side, model label on the top border's right side, and only the permission mode on the footer line. Refs #1894 --- crates/dim-cli/README.md | 2 +- crates/dim-cli/src/ui/tui.rs | 503 ++++++++++++++++------------ docs/architecture/tui-e2e.md | 1 + docs/design/cli-commands.md | 22 +- docs/design/cli-current-activity.md | 67 ++-- docs/design/model-configuration.md | 11 +- docs/design/timeline-ui.md | 6 +- docs/zh/design/cli-commands.md | 16 +- docs/zh/design/timeline-ui.md | 2 +- scripts/tui-tmux/scenarios.mjs | 123 ++++++- 10 files changed, 473 insertions(+), 280 deletions(-) diff --git a/crates/dim-cli/README.md b/crates/dim-cli/README.md index 6c46e39085..6146f43ce7 100644 --- a/crates/dim-cli/README.md +++ b/crates/dim-cli/README.md @@ -1152,7 +1152,7 @@ answer text (including its retained streaming tail) · stopped ``` -The fullscreen composer box has no prompt mark. The adopted model and, when its configuration carries one, the reasoning effort it sends (`provider / model · effort`) sit at the right of its top border. Its bottom border keeps the run status, status slot (a notice, `esc interrupt`, `permission required`), goal and main branch context reading (`1.8K / 256K`) at the left, and the attached Session's workspace and git branch at the right, with Home naming the launch directory. The permission preset is not in that border: both modes show the live permission footer described above, without an `AGENT` prefix, with its hint in the selected interface language. Scrollback retains its other status information, right-aligned model label and `›` prompt. 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. +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. 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. 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. diff --git a/crates/dim-cli/src/ui/tui.rs b/crates/dim-cli/src/ui/tui.rs index 120c1d2090..5bf6fec7c3 100644 --- a/crates/dim-cli/src/ui/tui.rs +++ b/crates/dim-cli/src/ui/tui.rs @@ -6277,69 +6277,67 @@ impl App { } } let box_top = live.len(); - let activity = |label: &str| fg(label, &p.activity); let shell_title = shell.map(|shell| match shell { Shell::Recorded => t("! shell mode"), Shell::Private => t("!! shell mode · not sent to the model"), }); - let tinted = |label: &str| fg(label, shell_color); - let top_status = status.as_deref().filter(|_| !self.fullscreen); - let title = match (top_status, shell_title) { - (Some(text), _) => Some((text, &activity as &dyn Fn(&str) -> String)), - (None, Some(title)) => Some((title, &tinted as &dyn Fn(&str) -> String)), - (None, None) => None, - }; let border = if shell.is_some() && self.prompt.is_none() { shell_color } else { &p.border }; let edge = |edge: &str| fg(edge, border); - let mut composer_box = boxed(&rows, cols, &edge, &|_, body| body.to_owned(), title); - if self.fullscreen { - let outer = cols.saturating_sub(2 + MARGIN).max(4); - let margin = " ".repeat(MARGIN); - let room = outer.saturating_sub(2); - let left = title.as_ref().map_or(0, |(text, _)| width_of(text) + 3); - let model = self - .label - .as_ref() - .and_then(|label| label.fitted(|text| left + width_of(text) + 3 < room)) - .map(|label| fg(&label, &p.highlight)); - if self.prompt.is_none() - && let Some(model) = &model - { - let end = MARGIN + outer - 3; - frame.model_label = Some((box_top, end - width_of(model)..end)); - } - let title = title.map(|(text, label)| label(text)); - let docked = self.dock_status(status.as_deref()); - let place = self.composer_place(docked.as_deref(), outer); - let last = composer_box.len() - 1; - composer_box[0] = format!( - "{margin}{}", - border_line(("╭", "╮"), title.as_deref(), model.as_deref(), outer, &edge) - ); - composer_box[last] = format!( - "{margin}{}", - border_line( - ("╰", "╯"), - docked.as_deref(), - place.as_deref(), - outer, - &edge - ) - ); - } else { - let outer = cols.saturating_sub(2 + MARGIN).max(4); - let margin = " ".repeat(MARGIN); - let place = self.composer_place(None, outer); - let last = composer_box.len() - 1; - composer_box[last] = format!( - "{margin}{}", - border_line(("╰", "╯"), None, place.as_deref(), outer, &edge) - ); + let mut composer_box = boxed(&rows, cols, &edge, &|_, body| body.to_owned(), None); + let outer = cols.saturating_sub(2 + MARGIN).max(4); + let margin = " ".repeat(MARGIN); + let room = outer.saturating_sub(2); + let max_border = outer.saturating_sub(6); + let title = shell_title + .map(|text| clip(text, max_border).0) + .filter(|text| !text.is_empty()) + .map(|text| fg(&text, shell_color)); + let left = title.as_deref().map_or(0, |text| width_of(text) + 3); + let model = self + .label + .as_ref() + .and_then(|label| label.fitted(|text| left + width_of(text) + 3 < room)) + .map(|label| fg(&label, &p.highlight)); + if self.fullscreen + && self.prompt.is_none() + && let Some(model) = &model + { + let end = MARGIN + outer - 3; + frame.model_label = Some((box_top, end - width_of(model)..end)); } + let docked = self.dock_status(status.as_deref()).and_then(|text| { + if width_of(&text) <= max_border { + return Some(text); + } + let (mut clipped, used) = clip(&text, max_border); + if used == 0 { + return None; + } + if clipped.contains('\x1b') && !clipped.ends_with("\x1b[0m") { + clipped.push_str("\x1b[0m"); + } + Some(clipped) + }); + let place = self.composer_place(docked.as_deref(), outer); + let last = composer_box.len() - 1; + composer_box[0] = format!( + "{margin}{}", + border_line(("╭", "╮"), title.as_deref(), model.as_deref(), outer, &edge) + ); + composer_box[last] = format!( + "{margin}{}", + border_line( + ("╰", "╯"), + docked.as_deref(), + place.as_deref(), + outer, + &edge + ) + ); let replaced = !command_entry && matches!( self.prompt, @@ -8230,17 +8228,6 @@ impl App { } } - fn slot_outranks_model(&self) -> bool { - match &self.notice { - Some(_) => true, - None if self.failure.is_some() => true, - None => matches!( - &self.snapshot, - Some(s) if !s.questions.is_empty() || !s.approvals.is_empty() - ), - } - } - /// How many tasks the Session runs apart from the turn, as its own /// status segment: none while every task has ended, so an idle Session /// with nothing in the background draws no segment at all. @@ -8310,8 +8297,9 @@ impl App { } } - /// Fullscreen's bottom border label, the status corner: the run - /// status, the slot (a notice in the highlight colour) and the context use. + /// The composer's bottom-left border label, the status corner: the run + /// status, the slot (a notice in the highlight colour), background task + /// count, goal and context use. fn dock_status(&self, run: Option<&str>) -> Option { let p = &self.palette; let mut parts: Vec = Vec::new(); @@ -8390,84 +8378,7 @@ impl App { let hint = fg(t("(shift+tab to cycle)"), &p.muted); let total = cols.saturating_sub(2); let prefix = format!("{}{permission}", " ".repeat(MARGIN)); - if self.fullscreen { - return clip(&format!("{prefix} {hint}"), total).0; - } - let goal = self - .goal_label() - .map(|goal| fg(&format!(" {goal}"), &p.muted)); - let context = self.context_label().map(|context| { - let color = if self.context_near() { - &p.warning - } else { - &p.muted - }; - fg(&format!(" {context}"), color) - }); - let slot = self.slot().map(|slot| { - let color = if self.notice.is_some() { - &p.highlight - } else { - &p.muted - }; - fg(&format!(" {slot}"), color) - }); - let background = self - .background_label() - .map(|background| fg(&format!(" {background}"), &p.muted)); - let width = |part: &Option| part.as_ref().map_or(0, |text| width_of(text)); - let prefix_width = width_of(&prefix); - let kept = if self.slot_outranks_model() { - width(&slot) - } else { - 0 - }; - let label = self.label.as_ref().and_then(|label| { - label.fitted(|text| prefix_width + kept + 2 + width_of(text) <= total) - }); - let render = |with_hint: bool| { - let mut head = prefix.clone(); - if with_hint { - head.push_str(&format!(" {hint}")); - } - let head_width = width_of(&head); - let label_width = label.as_ref().map_or(0, |text| width_of(text) + 2); - let room = total.saturating_sub(head_width + label_width); - let lead: String = [goal.clone(), context.clone()] - .into_iter() - .flatten() - .collect(); - let lead = if kept == 0 { - lead - } else { - clip(&lead, room.saturating_sub(kept + width(&background))).0 - }; - let mut rest = lead; - rest.push_str(slot.as_deref().unwrap_or_default()); - rest.push_str(background.as_deref().unwrap_or_default()); - let (rest, rest_used) = clip(&rest, room); - let content = head_width + rest_used; - let line = format!("{head}{rest}"); - match label { - Some(ref text) => { - let gap = total - content - width_of(text); - let line = format!( - "{line}{}{}", - " ".repeat(gap), - fg(text, &self.palette.highlight) - ); - (line, content) - } - None => (line, content), - } - }; - let (line, used) = render(false); - let label_room = label.as_ref().map_or(0, |text| 2 + width_of(text)); - if used + 1 + width_of(&hint) + label_room <= total { - render(true).0 - } else { - line - } + clip(&format!("{prefix} {hint}"), total).0 } } @@ -12086,6 +11997,22 @@ mod tests { home.path().to_path_buf(), "/work".into(), ); + let bottom = |app: &mut App| -> (String, String) { + let rows: Vec = app + .frame((160, 24)) + .live + .iter() + .map(|row| strip_escapes(row)) + .collect(); + let border = rows + .iter() + .rev() + .find(|row| row.contains('╰')) + .cloned() + .expect("composer bottom border"); + let footer = rows.last().cloned().expect("footer line"); + (border, footer) + }; app.apply(Update::Snapshot(Box::new(ViewSnapshot { session_id: "s1".into(), running: true, @@ -12095,39 +12022,41 @@ mod tests { ], ..ViewSnapshot::default() }))); - let line = strip_escapes(&app.status_line(160)); - assert!(line.contains("esc interrupt"), "{line}"); - assert!(line.contains("2 in background · /tasks"), "{line}"); - - let docked = app - .dock_status(Some("· working… 1s")) - .expect("a status corner"); - let docked = strip_escapes(&docked); - assert!(docked.contains("esc interrupt"), "{docked}"); - assert!(docked.contains("2 in background · /tasks"), "{docked}"); + for fullscreen in [false, true] { + app.fullscreen = fullscreen; + let (border, footer) = bottom(&mut app); + assert!(border.contains("esc interrupt"), "{border}"); + assert!(border.contains("2 in background · /tasks"), "{border}"); + assert!(footer.contains("Workspace write"), "{footer}"); + assert!(!footer.contains("esc interrupt"), "{footer}"); + assert!(!footer.contains("in background"), "{footer}"); + } let mut no_tasks = ViewSnapshot { session_id: "s1".into(), running: true, ..ViewSnapshot::default() }; + app.fullscreen = false; app.apply(Update::Snapshot(Box::new(no_tasks.clone()))); - let line = strip_escapes(&app.status_line(160)); - assert!(line.contains("esc interrupt"), "{line}"); - assert!(!line.contains("in background"), "{line}"); + let (border, footer) = bottom(&mut app); + assert!(border.contains("esc interrupt"), "{border}"); + assert!(!border.contains("in background"), "{border}"); + assert!(!footer.contains("esc interrupt"), "{footer}"); no_tasks.tasks = vec![background_task("t3", "cargo fmt")]; app.apply(Update::Snapshot(Box::new(no_tasks))); + let (border, _) = bottom(&mut app); assert!( - strip_escapes(&app.status_line(160)).contains("1 in background · /tasks"), - "a new task counts again" + border.contains("1 in background · /tasks"), + "a new task counts again: {border}" ); } /// A session that keeps every command the interface sends. struct Recorder(std::rc::Rc>>); - /// An 80-column scrollback app carrying `provider / model` with `effort`. + /// A scrollback app carrying `provider / model` with `effort`. fn status_app(provider: &str, model: &str, effort: Option<&str>) -> (App, tempfile::TempDir) { let theme = test_theme(); let home = tempfile::tempdir().unwrap(); @@ -12136,7 +12065,7 @@ mod tests { MarkdownRenderer::new(&theme), theme.palette.clone(), home.path().to_path_buf(), - "/work".into(), + "/private/tmp/dima-probe".into(), ); app.apply(Update::Ready(Configuration { provider_id: provider.into(), @@ -12150,78 +12079,224 @@ mod tests { (app, home) } - fn status_rows(app: &App) -> String { + fn composer_chrome(app: &mut App, cols: u16) -> (String, String, String) { use crate::ui::render::panel::strip_escapes; - strip_escapes(&app.status_line(80)) + let rows: Vec = app + .frame((cols, 24)) + .live + .iter() + .map(|row| strip_escapes(row)) + .collect(); + let top = rows + .iter() + .find(|row| row.contains('╭')) + .cloned() + .expect("composer top border"); + let bottom = rows + .iter() + .rev() + .find(|row| row.contains('╰')) + .cloned() + .expect("composer bottom border"); + let footer = rows.last().cloned().expect("footer line"); + (top, bottom, footer) } #[test] - fn a_slot_that_asks_the_user_keeps_its_text_before_the_shortcut_hint() { - let (mut app, _home) = status_app("test", "model", None); - app.set_notice("Press Ctrl+C again to exit"); - let line = status_rows(&app); - assert!(line.contains("Press Ctrl+C again to exit"), "{line}"); - assert!(line.contains("test / model"), "{line}"); - assert!(!line.contains("(shift+tab to cycle)"), "{line}"); - assert!(line.starts_with(" ⏵⏵ Workspace write"), "{line}"); + fn both_modes_unify_composer_borders_and_keep_permission_only_on_the_footer() { + let (mut app, _home) = status_app("local", "fixture-model", Some("high")); + app.context = Some(crate::model::session::ContextReading { + input: 98_300, + window: 1_000_000, + threshold: 900_000, + }); + + // Idle: both borders carry no run status or interrupt hint. + for fullscreen in [false, true] { + app.fullscreen = fullscreen; + let (top, bottom, footer) = composer_chrome(&mut app, 100); + assert!(top.contains("local / fixture-model · high"), "{top}"); + assert!( + !top.contains("thinking…") && !top.contains("working…"), + "{top}" + ); + assert!( + !bottom.contains("thinking…") && !bottom.contains("working…"), + "{bottom}" + ); + assert!(!bottom.contains("esc interrupt"), "{bottom}"); + assert!(bottom.contains("98.3K / 1M"), "{bottom}"); + assert!(bottom.contains("/private/tmp/dima-probe"), "{bottom}"); + assert!( + footer.contains("⏵⏵ Workspace write (shift+tab to cycle)"), + "{footer}" + ); + assert!(!footer.contains("local / fixture-model"), "{footer}"); + assert!(!footer.contains("98.3K / 1M"), "{footer}"); + } + + // Running thinking turn: status, slot and usage share bottom-left; model sits top-right; + // nothing is duplicated onto the footer. + let mut thinking_row = (*message(false)).clone(); + thinking_row.row_id = "t1".into(); + thinking_row.kind = RowKind::Thinking; + thinking_row.text = "thinking about it".into(); + thinking_row.streaming = true; + app.apply(Update::Snapshot(Box::new(ViewSnapshot { + session_id: "s1".into(), + running: true, + rows: vec![std::sync::Arc::new(thinking_row)], + ..ViewSnapshot::default() + }))); + for fullscreen in [false, true] { + app.fullscreen = fullscreen; + let (top, bottom, footer) = composer_chrome(&mut app, 100); + assert!(top.contains("local / fixture-model · high"), "{top}"); + assert!(!top.contains("thinking…"), "{top}"); + assert!(bottom.contains("thinking…"), "{bottom}"); + assert!(bottom.contains("esc interrupt"), "{bottom}"); + assert!(bottom.contains("98.3K / 1M"), "{bottom}"); + assert!(bottom.contains("/private/tmp/dima-probe"), "{bottom}"); + assert!( + footer.contains("⏵⏵ Workspace write (shift+tab to cycle)"), + "{footer}" + ); + assert!(!footer.contains("esc interrupt"), "{footer}"); + assert!(!footer.contains("98.3K / 1M"), "{footer}"); + assert!(!footer.contains("local / fixture-model"), "{footer}"); + + // Narrow (60 cols): status, slot and usage fit bottom-left; place cuts from left. + let (top, bottom, footer) = composer_chrome(&mut app, 60); + assert!(top.contains("local / fixture-model · high"), "{top}"); + assert!(!top.contains("thinking…"), "{top}"); + assert!(bottom.contains("thinking…"), "{bottom}"); + assert!(bottom.contains("esc interrupt"), "{bottom}"); + assert!(bottom.contains("98.3K / 1M"), "{bottom}"); + assert!( + bottom.contains('…'), + "place shortens from the left: {bottom}" + ); + assert!(!footer.contains("esc interrupt"), "{footer}"); + assert!(!footer.contains("local / fixture-model"), "{footer}"); - app.set_notice("/rename needs a session"); - let line = status_rows(&app); - assert!(line.contains("/rename needs a session"), "{line}"); - assert!(line.contains("test / model"), "{line}"); - assert!(!line.contains("(shift+tab to cycle)"), "{line}"); + // Very narrow (24 cols): status keeps its phase ahead of elapsed/slot; model drops. + let (top, bottom, _) = composer_chrome(&mut app, 24); + assert!(!top.contains("local / fixture-model"), "{top}"); + assert!(bottom.contains("thinking…"), "{bottom}"); + } } #[test] - fn a_slot_that_asks_the_user_outranks_a_long_model_label() { - let (mut app, _home) = status_app("deepseek", "deepseek-v4.1-flash", Some("max")); + fn scrollback_composer_handles_notices_approvals_questions_retry_disconnect_shell_and_unread() { + use crate::model::view::{ApprovalView, RetryView}; + use dim_agent_types::ModelFailureKind; + + let (mut app, _home) = status_app("local", "fixture-model", None); + + // Notice: bottom border, while model stays top-right and permission stays on footer. app.set_notice("Press Ctrl+C again to exit"); - let line = status_rows(&app); - assert!(line.contains("Press Ctrl+C again to exit"), "{line}"); + let (top, bottom, footer) = composer_chrome(&mut app, 100); + assert!(top.contains("local / fixture-model"), "{top}"); + assert!(bottom.contains("Press Ctrl+C again to exit"), "{bottom}"); assert!( - !line.contains("deepseek / deepseek-v4.1-flash"), - "the model name gives up its cells and then its place: {line}" + footer.contains("⏵⏵ Workspace write (shift+tab to cycle)"), + "{footer}" ); - } + assert!(!footer.contains("Press Ctrl+C again to exit"), "{footer}"); + assert!(!footer.contains("local / fixture-model"), "{footer}"); + app.notice = None; - #[test] - fn a_run_state_slot_still_yields_to_the_model_label() { - let (mut app, _home) = status_app("deepseek", "deepseek-v4.1-flash", Some("max")); + // Approval slot (when composer is visible). app.apply(Update::Snapshot(Box::new(ViewSnapshot { session_id: "s1".into(), - running: true, + approvals: vec![ApprovalView { + member: None, + branch_id: "main".into(), + request_id: "req-1".into(), + tool_name: "exec".into(), + reason: "run".into(), + tool_input: serde_json::json!({"command": "echo hi"}), + always: None, + }], ..ViewSnapshot::default() }))); - let line = status_rows(&app); - assert!(line.contains("esc interrupt"), "{line}"); - assert!( - line.contains("deepseek / deepseek-v4.1-flash · max"), - "the model keeps its place and its effort: {line}" - ); + app.prompt = None; + let (_, bottom, footer) = composer_chrome(&mut app, 100); + assert!(bottom.contains("permission required"), "{bottom}"); + assert!(!footer.contains("permission required"), "{footer}"); + + // Question slot (when composer is visible). + app.apply(Update::Snapshot(Box::new(ViewSnapshot { + session_id: "s1".into(), + questions: vec![questions()], + ..ViewSnapshot::default() + }))); + app.prompt = None; + let (_, bottom, footer) = composer_chrome(&mut app, 100); + assert!(bottom.contains("answer required"), "{bottom}"); + assert!(!footer.contains("answer required"), "{footer}"); - let (mut wide, _home) = - status_app("anthropic", "gpt-5-codex-long-context-preview-2026", None); - wide.apply(Update::Snapshot(Box::new(ViewSnapshot { + // Retry countdown at 100 and 60 cols: stays on bottom border and is clipped rather than dropped. + app.apply(Update::Snapshot(Box::new(ViewSnapshot { session_id: "s1".into(), running: true, + retry: Some(RetryView { + attempt: 2, + max_attempts: 8, + retry_at_ms: retry_at(30_000), + kind: ModelFailureKind::ServerError, + reason: Some("The server is overloaded".into()), + }), ..ViewSnapshot::default() }))); - let line = status_rows(&wide); - assert!( - line.contains("anthropic / gpt-5-codex-long-context-preview-2026"), - "a run state yields to the model label: {line}" - ); - } + for cols in [100, 60] { + let (top, bottom, footer) = composer_chrome(&mut app, cols); + assert!(!top.contains("Retrying"), "{cols}: {top}"); + assert!(bottom.contains("Retrying 2/8 in"), "{cols}: {bottom}"); + assert!(!footer.contains("Retrying"), "{cols}: {footer}"); + } - #[test] - fn a_wide_status_line_shows_the_hint_the_model_and_the_slot() { - use crate::ui::render::panel::strip_escapes; - let (mut app, _home) = status_app("test", "model", None); - app.set_notice("Press Ctrl+C again to exit"); - let line = strip_escapes(&app.status_line(160)); - assert!(line.contains("(shift+tab to cycle)"), "{line}"); - assert!(line.contains("Press Ctrl+C again to exit"), "{line}"); - assert!(line.contains("test / model"), "{line}"); + // Disconnect notice on bottom border. + app.apply(Update::Snapshot(Box::new(ViewSnapshot { + session_id: "s1".into(), + ..ViewSnapshot::default() + }))); + app.failure = Some("daemon disconnected".into()); + let (_, bottom, footer) = composer_chrome(&mut app, 100); + assert!(bottom.contains("Disconnected · draft kept"), "{bottom}"); + assert!(!footer.contains("Disconnected · draft kept"), "{footer}"); + app.failure = None; + + // Shell mode keeps top-border left title beside top-right model label. + app.handle_input(InputEvent::Key(crate::ui::terminal::KeyEvent::new( + KeyCode::Char('!'), + Modifiers::NONE, + ))); + let (top, bottom, _) = composer_chrome(&mut app, 100); + assert!(top.contains("! shell mode"), "{top}"); + assert!(top.contains("local / fixture-model"), "{top}"); + assert!(!bottom.contains("! shell mode"), "{bottom}"); + app.handle_input(InputEvent::Key(crate::ui::terminal::KeyEvent::new( + KeyCode::Backspace, + Modifiers::NONE, + ))); + + // Unread badge shares bottom-right with place and yields to left status at narrow width. + let mut unread = ViewSnapshot { + session_id: "s1".into(), + running: true, + ..ViewSnapshot::default() + }; + unread.unread_lines.insert("b-7c".into()); + app.apply(Update::Snapshot(Box::new(unread))); + let (_, wide_bottom, _) = composer_chrome(&mut app, 100); + assert!(wide_bottom.contains("working…"), "{wide_bottom}"); + assert!(wide_bottom.contains("esc interrupt"), "{wide_bottom}"); + assert!(wide_bottom.contains("Unread (1) · /lines"), "{wide_bottom}"); + let (_, narrow_bottom, _) = composer_chrome(&mut app, 60); + assert!(narrow_bottom.contains("working…"), "{narrow_bottom}"); + assert!(narrow_bottom.contains("esc interrupt"), "{narrow_bottom}"); + assert!(narrow_bottom.contains("/lines (1)"), "{narrow_bottom}"); } impl SessionPort for Recorder { @@ -12270,9 +12345,9 @@ mod tests { }); assert_eq!( label, - match (fullscreen, cols) { - (_, 100) => Some("test / model · high"), - (true, 26) => Some("test / model"), + match cols { + 100 => Some("test / model · high"), + 26 => Some("test / model"), _ => None, } ); @@ -12729,7 +12804,7 @@ mod tests { let live = crate::ui::render::panel::strip_escapes(&app.frame((100, 40)).live.join("\n")); let row = live .lines() - .find(|line| line.contains("Prompt suggestion")) + .find(|line| line.contains('│') && line.contains("Prompt suggestion")) .expect("the switch's row"); assert!( row.contains(t("Not available")), diff --git a/docs/architecture/tui-e2e.md b/docs/architecture/tui-e2e.md index 0dc1582f76..830d1eca49 100644 --- a/docs/architecture/tui-e2e.md +++ b/docs/architecture/tui-e2e.md @@ -110,6 +110,7 @@ daemon. `--keep` leaves the home and raw streams in place for inspection. | commands | `slash_palette_lists_curated_commands_and_settings` | The palette's curated order and filter, the Settings panel, and `/keys` output | | commands | `palette_tab_completes_and_enter_runs_the_command` | `Tab` completes the command without running it, three `Tab`s keep completing and never exit the palette, and `Enter` still runs it, in both layouts | | runs | `streaming_status_reports_and_interrupts` | The status row says `working…`/`esc interrupt`, OSC 7501 reports `working`, `Escape` interrupts with the recorded reason, and the status settles; with `DIM_TERMINAL_PROGRESS=on`, OSC 9;4 draws the working bar and takes it down when the run settles, and the last sequence the pane receives after exit is that clear | +| runs | `composer_borders_match_in_scrollback_and_fullscreen` | A slow-thinking turn in both scrollback and fullscreen at 100 and 60 columns places the run status, `esc interrupt`, and context usage together on the composer's bottom border, keeps the model on the top border (beside `! shell mode` in scrollback), and leaves only the permission preset on the footer line | | input-queue | `queue_holds_steers_and_deletes` | Held messages in queue mode, the `Queue (n)` strip, `/queue`, `x` deletion read from the panel's own rows, `Enter` steer, the applied row in the transcript, and the deleted input never entering it | | approvals | `approval_panel_allows_one_command` | The permission panel names the tool and command, `y` allows once, the command output returns to the model, and the status is blocked before the answer | | approvals | `question_panel_answer_reaches_the_next_request` | The question panel's options, the review step, and the chosen label in the tool result the model receives | diff --git a/docs/design/cli-commands.md b/docs/design/cli-commands.md index 270dcde1ac..04a85de122 100644 --- a/docs/design/cli-commands.md +++ b/docs/design/cli-commands.md @@ -3109,11 +3109,11 @@ Assistant: ... Both TUI modes draw a live permission footer under the composer, without an `AGENT` prefix; the preset, colors, localized shortcut hint and key behavior are defined in [`/permissions`](#permissions). It is not committed to transcript history. -Scrollback keeps the goal marker, context use against its window, and one slot for the state -in force — a notice, a required answer or permission, `esc interrupt`, or the background task -count — on the same line. The model, with its effort when both fit, is right-aligned there; -the line is clipped to the terminal width. Fullscreen instead keeps run status, the status -slot, goal and context information in the composer border, not the permission preset. +Both modes place the model label (with its effort when both fit) on the right side of the +composer's top border, and keep the run status, the status slot (a notice, a required answer +or permission, `esc interrupt`, or disconnect), background task count, goal and context +information on the left side of the composer's bottom border, leaving only the permission +preset and its shortcut hint on the footer line. ### Submit check warnings @@ -3277,14 +3277,10 @@ The three rows above are alternatives: only the effective preset appears. The sh is translated into the selected interface language. Read only is cyan, Workspace write is purple and Full access is yellow; the shortcut hint is muted. Light themes use darker shades for contrast, and limited-color terminals use their cyan, magenta and yellow -slots. The permission label takes priority over the hint and other status content on narrow -terminals. Fullscreen retains run, goal, context and notice information in the composer border. -In scrollback the hint ranks last: the permission label is drawn first and the hint only when -the whole line still fits with it, so the hint's cells go to the rest when they are needed. A -slot that asks the user something or reports a problem, which is a notice, the disconnected -text, `answer required` and `permission required`, outranks the right-aligned model: the model -gives up its effort first, then its place while that slot shows. `esc interrupt`, goal, context -and background text still yield to the model, which keeps its space before they are clipped. +slots. The permission label takes priority over the hint on narrow terminals, where the line +is clipped to the terminal width. Both modes keep run status, the status slot, background +task count, goal and context information on the composer's bottom border, and the model label +on the composer's top border. With the composer owning the keys, Shift+Tab cycles Read only → Workspace write → Full access → Read only without submitting or changing the draft, including during a running turn. It diff --git a/docs/design/cli-current-activity.md b/docs/design/cli-current-activity.md index a386e3bfd2..5072e1c982 100644 --- a/docs/design/cli-current-activity.md +++ b/docs/design/cli-current-activity.md @@ -30,9 +30,14 @@ strip. The strip by itself establishes no foreground wait. An idle line keeps the existing idle treatment when there is no confirmed background work. `LineState::Waiting` means an open line with no running turn. -In scrollback the run status is the composer’s top border title. Fullscreen -keeps it in the lower dock. The place and unread badge continue to share the -right side of the bottom border. Keep the existing notice slots and +Both modes use the same composer layout: the run status, status slot +(`esc interrupt`, notices, `permission required` / `answer required`, +disconnect), background task count, goal and context usage share the left side +of the composer’s bottom border. The place and unread badge continue to share +the right side of the bottom border. The model label sits on the right side of +the top border, while shell mode keeps the top-border left title. The footer +line below the composer keeps only the permission mode in both modes. Keep the +existing notice slots and [notification and clipping priorities](timeline-ui.md#unread-replies). Shorten the status within its existing space by terminal cell width. Preserve the phase and any known object ahead of optional elapsed text. @@ -46,29 +51,29 @@ Scrollback during a dispatched batch at the default tool detail setting: > Fix the issue and verify [committed tool history] - o CI checks 2m13s -+-- Tool batch pending ------------------------+ -| > | -+------------------------ Unread (1) · /lines -+ + o CI checks 2m13s ++----------------------------------- provider / model -+ +| > | ++-- Tool batch pending ---------- Unread (1) · /lines -+ ``` Scrollback while the model generates and a server runs in the background: ```text - o Dev server 8m02s -+-- Generating · this turn 24s ----------------+ -| > | -+------------------------------------- ~/repo -+ + o Dev server 8m02s ++----------------------------------- provider / model -+ +| > | ++-- Generating · this turn 24s --------------- ~/repo -+ ``` The same generating state in narrow scrollback, with both elapsed labels -omitted and the task still visible: +omitted, the model label dropped to fit, and the task still visible: ```text o Dev server -+-- Generating ----------------+ ++------------------------------+ | > | -+--------------------- ~/repo -+ ++-- Generating ------- ~/repo -+ ``` The task row’s elapsed time comes from the task’s own start. Show “this turn” @@ -166,19 +171,19 @@ an admitted wait with an authoritative start. Conditional scrollback and fullscreen examples: ```text - o CI checks 2m13s -+-- Waiting for task: CI checks · wait 1m40s ----------+ -| > | -+--------------------------------------------- ~/repo -+ - -+--------------------------------------------------------------+ -| [tool history at current detail setting] | -| | -| o CI checks 2m13s | -| +----------------------------------------------------------+ | -| | > | | -| +-- Waiting for task: CI checks · wait 1m40s ----- ~/repo -+ | -+--------------------------------------------------------------+ + o CI checks 2m13s ++----------------------------------------- provider / model -+ +| > | ++-- Waiting for task: CI checks · wait 1m40s ------- ~/repo -+ + ++----------------------------------------------------------------+ +| [tool history at current detail setting] | +| | +| o CI checks 2m13s | +| +----------------------------------------- provider / model -+ | +| | > | | +| +-- Waiting for task: CI checks · wait 1m40s ------- ~/repo -+ | ++----------------------------------------------------------------+ ``` ## Cost and terminal signaling @@ -212,10 +217,10 @@ adopted inputs. Repainting adds zero RPCs, history scans or remote CI polls. OSC bytes independently through the existing terminal status checks. - With a disposable `DIMCODE_HOME` and deterministic provider, capture both modes at 100, 60 and 32 columns using a synthetic “CI checks” task. - Check the scrollback top border and fullscreen lower dock, the - place/unread label and notifications, default visibility without - `/tasks`, history scroll, detail toggles, branch changes, disconnect, - stop and resume. This scenario can join the local tmux suite under + Check the unified composer borders (top-right model label and bottom-left + status dock) in both modes, the place/unread label and notifications, default + visibility without `/tasks`, history scroll, detail toggles, branch changes, + disconnect, stop and resume. This scenario can join the local tmux suite under [#1803](https://github.com/arcships/dim/issues/1803) when it lands. Until then, use the existing isolated local terminal harness. - After an owner contract is approved, separately verify the named status diff --git a/docs/design/model-configuration.md b/docs/design/model-configuration.md index f1eece2f10..0feb35f77d 100644 --- a/docs/design/model-configuration.md +++ b/docs/design/model-configuration.md @@ -558,12 +558,11 @@ configuration-superseded, reload/interruption and Session-closed contracts. ## Scrollback interaction Both native TUI modes draw the model label and its effective reasoning effort -in the theme's highlight colour. Scrollback keeps this label in its bottom status -row; fullscreen keeps it on the composer's top border. With fullscreen mouse -reporting enabled, clicking the visible model label opens the existing `/models` -picker without discarding the draft. Only a press and release on the same label -cell counts; dragging, resizing, a hidden label or an open overlay cannot activate -it. Esc closes the picker and returns to the draft. +in the theme's highlight colour on the right side of the composer's top border. +With fullscreen mouse reporting enabled, clicking the visible model label opens +the existing `/models` picker without discarding the draft. Only a press and +release on the same label cell counts; dragging, resizing, a hidden label or an +open overlay cannot activate it. Esc closes the picker and returns to the draft. ```text ╭────────────────────── provider / model · high ─╮ diff --git a/docs/design/timeline-ui.md b/docs/design/timeline-ui.md index 3eadeb6f43..1f1a2eb26b 100644 --- a/docs/design/timeline-ui.md +++ b/docs/design/timeline-ui.md @@ -250,7 +250,7 @@ The composer's bottom border shows how many other lines have unread reply text. The Session worker derives the indicator from nonblank assistant text in live `session.event` records. Text in the shown transcript or open side panel is already seen. The badge counts lines and stays until each is opened. History pages and repeated events leave the indicator alone. The worker keeps reply and acknowledgment positions for the current attachment. A fresh attachment starts without unread marks and presents existing replies as history. The position used here concerns what the user saw in that line's transcript. -The notification shares the existing bottom border in both TUI modes. Narrow widths favor the notification over the directory label. It shortens to `/lines (N)`, then `/lines`, then `*` as the room decreases. The existing left status in fullscreen keeps priority. +The notification shares the existing bottom border in both TUI modes. Narrow widths favor the notification over the directory label. It shortens to `/lines (N)`, then `/lines`, then `*` as the room decreases. The left status on the bottom border keeps priority in both modes. ## 7. Client data @@ -285,8 +285,8 @@ The notification shares the existing bottom border in both TUI modes. Narrow wid ## Proposed current activity in the composer -[CLI current activity](cli-current-activity.md) uses the existing live composer -status at the top of the scrollback composer and in the fullscreen lower dock. +[CLI current activity](cli-current-activity.md) uses the live composer status on +the bottom border in both TUI modes. The bottom-border place and unread label keep their existing priorities. Committed tool history keeps its existing detail and scrolling behavior. The background task strip continues to show task lifetimes independently of the diff --git a/docs/zh/design/cli-commands.md b/docs/zh/design/cli-commands.md index 6673fb81a7..6625f64962 100644 --- a/docs/zh/design/cli-commands.md +++ b/docs/zh/design/cli-commands.md @@ -1870,9 +1870,9 @@ Assistant: ... 两种 TUI 模式都在输入框下方绘制实时权限页脚,不带 `AGENT` 前缀;预设、颜色、本地化快捷键提示与 按键行为见 [`/permissions`](#permissions)。页脚不提交到正文历史。 -Scrollback 在同一行保留目标标记、上下文对窗口的占用,以及一个显示当前状态的槽位——通知、需要回答 -或审批、`esc interrupt` 或后台任务数。模型(放得下时连同推理强度)靠右对齐;整行按终端宽度截断。 -Fullscreen 则在输入框下边框保留运行状态、状态槽、目标与上下文信息,不再把权限预设放进边框。 +两种模式都把模型标签(放得下时连同推理强度)放在输入框上边框右侧,把运行状态、状态槽(通知、需要回答 +或审批、`esc interrupt` 或断连)、后台任务数、目标与上下文信息放在输入框下边框左侧;页脚行只保留 +权限预设及其快捷键提示。 ### 提交检查的警告 @@ -1952,13 +1952,9 @@ Esc 返回本面板并保持 Command rules 行的焦点。两种 TUI 模式都 上面三行是互斥示例,实际只显示当前生效的预设。快捷键提示随界面语言翻译。Read only 为青色, Workspace write 为紫色,Full access 为黄色,快捷键提示为灰色。浅色主题用更深的颜色保证对比度, -有限色终端使用青、品红、黄调色板。窄终端优先保留权限名称,再显示提示与其他状态内容。 -Fullscreen 的运行、目标、上下文和通知信息仍在输入框边框内。 -Scrollback 中提示排在最末:先画权限名称,只有在整行仍放得下时才画提示, -需要的空间不足时提示让出的宽度留给其余内容。需要用户回应或报告问题的槽位—— -通知、断连文本、`answer required` 与 `permission required`——优先于右对齐的模型: -模型先去掉 effort,再在该槽位显示期间让出位置。`esc interrupt`、目标、上下文和后台任务文字 -仍让位于模型,模型先占位,它们再被裁剪。 +有限色终端使用青、品红、黄调色板。窄终端优先保留权限名称,整行按终端宽度截断。 +两种模式都把运行状态、状态槽、后台任务数、目标和上下文信息放在输入框下边框,模型标签放在输入框 +上边框。 输入框拥有按键时,Shift+Tab 按 Read only → Workspace write → Full access → Read only 循环, 不提交或修改草稿,运行中同样可用。它复用选择器的预设选择操作与记住的偏好;快速连按按顺序处理, diff --git a/docs/zh/design/timeline-ui.md b/docs/zh/design/timeline-ui.md index 560026c702..78baedc119 100644 --- a/docs/zh/design/timeline-ui.md +++ b/docs/zh/design/timeline-ui.md @@ -240,7 +240,7 @@ fork 是别的 Session,归 `/resume`;fork 出来的会话自己的默认分 Session worker 通过实时 `session.event` 中非空白的 assistant 正文判断新回答。已显示的分支和已打开的侧面板视为已读。提示按分支计数,历史加载和重复事件不会重新点亮提示。回答及用户已读位置只保存在当前 attachment 内。新 attachment 从空标记开始,旧回答仍可作为历史查看。 -两种 TUI 模式都复用输入框底栏。空间不足时优先显示提醒,按可用宽度依次缩成 `/lines (N)`、`/lines`、`*`。全屏模式仍优先保留左侧状态。 +两种 TUI 模式都复用输入框底栏。空间不足时优先显示提醒,按可用宽度依次缩成 `/lines (N)`、`/lines`、`*`。两种模式都优先保留下边框左侧状态。 ## 7. 客户端数据 diff --git a/scripts/tui-tmux/scenarios.mjs b/scripts/tui-tmux/scenarios.mjs index d1c98e3835..fd250e3adf 100644 --- a/scripts/tui-tmux/scenarios.mjs +++ b/scripts/tui-tmux/scenarios.mjs @@ -828,6 +828,121 @@ const scenarios = [ assert.equal(raw.slice(last, last + bar('0').length), bar('0'), 'no progress bar remains after exit'); }, }, + { + name: 'composer_borders_match_in_scrollback_and_fullscreen', + area: 'runs', + title: 'Scrollback and fullscreen share the same composer border layout at 100 and 60 columns', + async run(tui) { + const USAGE = /\d+(?:\.\d+)?[KM]?\s*\/\s*128K/; + await tui.setup({ + respond: (request) => { + if ((request.tools ?? []).length === 0) return {text: ANSWER}; + if (userText(request).includes('slow think')) { + return { + thinking: 'thinking about it '.repeat(60), + text: 'Thinking done.', + chunkSize: 4, + chunkDelayMs: 120, + }; + } + return {text: ANSWER}; + }, + }); + + const composerChrome = (terminal) => { + const lines = terminal + .capture({join: false}) + .split('\n') + .map((line) => line.trimEnd()) + .filter(Boolean); + const top = [...lines].reverse().find((line) => line.includes('╭') && line.includes('╮')) ?? ''; + const bottom = [...lines].reverse().find((line) => line.includes('╰') && line.includes('╯')) ?? ''; + const footer = [...lines].reverse().find((line) => line.includes('Workspace write')) ?? ''; + return {top, bottom, footer, lines}; + }; + + const assertRunningChrome = (chrome, mode, cols) => { + const ctx = `${mode} ${cols} cols:\n${chrome.lines.join('\n')}`; + assert(chrome.top.includes('local / fixture-model'), `model on top border (${ctx})`); + assert(!chrome.top.includes('thinking…'), `status not on top border (${ctx})`); + assert(chrome.bottom.includes('thinking…'), `thinking status on bottom border (${ctx})`); + assert(chrome.bottom.includes('esc interrupt'), `esc interrupt on bottom border (${ctx})`); + assert(USAGE.test(chrome.bottom), `context usage on bottom border (${ctx})`); + assert(chrome.footer.includes('Workspace write'), `permission preset on footer (${ctx})`); + assert(!chrome.footer.includes('esc interrupt'), `no esc interrupt on footer (${ctx})`); + assert(!chrome.footer.includes('local / fixture-model'), `no model on footer (${ctx})`); + assert(!USAGE.test(chrome.footer), `no usage on footer (${ctx})`); + }; + + for (const [mode, args] of [ + ['scrollback', []], + ['fullscreen', ['--fullscreen']], + ]) { + const terminal = await tui.launch(args, {cols: 100, rows: 24, waitForComposer: true}); + + // Complete one fast turn so the Session exists and context usage is shown. + await terminal.sendPrompt('seed usage'); + await terminal.waitFor(ANSWER); + await terminal.waitFor(USAGE, {describe: `${mode} context usage reading`}); + + const idle = composerChrome(terminal); + assert(idle.top.includes('local / fixture-model'), `${mode} idle top border carries model:\n${idle.top}`); + assert(!idle.top.includes('thinking…') && !idle.top.includes('working…'), `${mode} idle top has no status`); + assert(!idle.bottom.includes('thinking…') && !idle.bottom.includes('esc interrupt'), `${mode} idle bottom has no run status`); + assert(USAGE.test(idle.bottom), `${mode} idle bottom carries context usage:\n${idle.bottom}`); + assert(!idle.footer.includes('local / fixture-model') && !USAGE.test(idle.footer), `${mode} idle footer keeps only permission:\n${idle.footer}`); + + if (mode === 'scrollback') { + terminal.send('!'); + await terminal.waitFor('! shell mode'); + const shellChrome = composerChrome(terminal); + assert( + shellChrome.top.includes('! shell mode') && shellChrome.top.includes('local / fixture-model'), + `shell mode keeps top-border title beside model:\n${shellChrome.top}`, + ); + terminal.key('BSpace'); + await terminal.waitForAbsent('! shell mode'); + } + + terminal.send('slow think'); + terminal.key('Enter'); + await terminal.waitFor('thinking…'); + await terminal.waitFor('esc interrupt'); + assertRunningChrome(composerChrome(terminal), mode, 100); + + // Shrink to 60 columns while the slow-thinking turn is running. + terminal.resize(60, 24); + const deadline = Date.now() + 20_000; + let narrow = null; + for (;;) { + const chrome = composerChrome(terminal); + const widest = Math.max(0, ...chrome.lines.map((line) => line.length)); + if ( + widest <= 60 && + chrome.top.includes('local / fixture-model') && + chrome.bottom.includes('thinking…') && + chrome.bottom.includes('esc interrupt') && + USAGE.test(chrome.bottom) + ) { + narrow = chrome; + break; + } + if (Date.now() >= deadline) { + throw new Error( + `${mode} did not repaint unified composer at 60 cols within 20000ms (widest ${widest})\n${chrome.lines.join('\n')}`, + ); + } + await sleep(100); + } + assertRunningChrome(narrow, mode, 60); + + terminal.key('Escape'); + await terminal.waitFor('stopped'); + await terminal.untilComposer(); + await exitWith(terminal); + } + }, + }, { name: 'queue_holds_steers_and_deletes', area: 'input-queue', @@ -900,7 +1015,6 @@ const scenarios = [ await terminal.waitFor('Permission required'); await terminal.waitFor('echo fixture-ok'); await terminal.waitFor('Allow once'); - await terminal.waitFor('permission required'); await terminal.waitForRaw((raw) => raw.includes('state=blocked:kind=permission'), { describe: 'the blocked status', }); @@ -954,7 +1068,14 @@ const scenarios = [ terminal.key('Enter'); await terminal.waitFor('Which fixture should I use?'); await terminal.waitFor('Option A'); + await terminal.waitForRaw((raw) => raw.includes('state=blocked:kind=question'), { + describe: 'the blocked question status', + }); + // Opening `/` over a question restores the composer with `answer required` on its bottom border. + terminal.send('/'); await terminal.waitFor('answer required'); + terminal.key('Escape'); + await terminal.waitFor('Option A'); terminal.key('Down'); terminal.key('Enter'); From cf6198ea9037000766fdfefb235bbd7d35f196f5 Mon Sep 17 00:00:00 2001 From: zjywill Date: Fri, 20 Nov 2026 16:31:01 +0800 Subject: [PATCH 2/8] tui: keep the status slot visible while a prompt replaces the composer A prompt that replaces the composer (approval, question, queue, timeline and similar) hides the composer's bottom border, which was the only place the status slot was drawn. A disconnect or a required answer then showed nowhere in scrollback, and in fullscreen too. While the composer is replaced, the footer line now carries the slot, once; the composer keeps drawing it on its bottom border when it is shown. Refs #1894 --- crates/dim-cli/README.md | 2 +- crates/dim-cli/src/ui/tui.rs | 86 ++++++++++++++++++++++++++++- docs/design/cli-commands.md | 5 +- docs/design/cli-current-activity.md | 6 +- 4 files changed, 92 insertions(+), 7 deletions(-) diff --git a/crates/dim-cli/README.md b/crates/dim-cli/README.md index 6146f43ce7..83b4eb150c 100644 --- a/crates/dim-cli/README.md +++ b/crates/dim-cli/README.md @@ -1152,7 +1152,7 @@ answer text (including its retained streaming tail) · stopped ``` -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. 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. +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, the footer also shows the status slot, once. 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. 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. diff --git a/crates/dim-cli/src/ui/tui.rs b/crates/dim-cli/src/ui/tui.rs index 5bf6fec7c3..490e9cc7ff 100644 --- a/crates/dim-cli/src/ui/tui.rs +++ b/crates/dim-cli/src/ui/tui.rs @@ -6509,7 +6509,7 @@ impl App { if let Some(panel) = panel { live.extend(panel.into_iter().map(|row| format!("{margin}{row}"))); } - live.push(self.status_line(cols)); + live.push(self.status_line(cols, replaced)); let composer_cursor = ( (box_top + 1 + cursor_row) as u16, (MARGIN + 2 + cursor_col).min(cols.saturating_sub(1)) as u16, @@ -8365,7 +8365,10 @@ impl App { } } - fn status_line(&self, cols: usize) -> String { + /// The footer line: the permission mode, plus the status slot while a + /// prompt replaces the composer, because the composer's bottom border + /// (which otherwise carries the slot) is not drawn then. + fn status_line(&self, cols: usize, replaced: bool) -> String { use dim_agent_types::PermissionPreset; let p = &self.palette; let preset = self.permission_policy.preset; @@ -8378,7 +8381,23 @@ impl App { let hint = fg(t("(shift+tab to cycle)"), &p.muted); let total = cols.saturating_sub(2); let prefix = format!("{}{permission}", " ".repeat(MARGIN)); - clip(&format!("{prefix} {hint}"), total).0 + let slot = replaced.then(|| self.slot()).flatten().map(|slot| { + let color = if self.notice.is_some() { + &p.highlight + } else { + &p.muted + }; + fg(&slot, color) + }); + let Some(slot) = slot else { + return clip(&format!("{prefix} {hint}"), total).0; + }; + let with_hint = format!("{prefix} {hint} {slot}"); + if width_of(&with_hint) <= total { + with_hint + } else { + clip(&format!("{prefix} {slot}"), total).0 + } } } @@ -12102,6 +12121,67 @@ mod tests { (top, bottom, footer) } + #[test] + fn a_disconnect_stays_visible_once_while_a_prompt_replaces_the_composer() { + use crate::ui::render::panel::strip_escapes; + const SLOT: &str = "Disconnected · draft kept"; + fn count(app: &mut App, fullscreen: bool) -> usize { + app.fullscreen = fullscreen; + app.frame((100, 24)) + .live + .iter() + .map(|row| strip_escapes(row)) + .filter(|row| row.contains(SLOT)) + .count() + } + + for fullscreen in [false, true] { + let (mut app, _home) = status_app("local", "fixture-model", Some("high")); + let open = ViewSnapshot { + approvals: vec![crate::model::view::ApprovalView { + member: None, + request_id: "r1".into(), + branch_id: "main".into(), + reason: "shell command".into(), + tool_name: "exec".into(), + tool_input: serde_json::Value::Null, + always: None, + }], + ..ViewSnapshot::default() + }; + app.apply(Update::Snapshot(Box::new(open))); + app.apply(Update::Failed("daemon disconnected".into())); + assert!(matches!(app.prompt, Some(Prompt::Permission(_)))); + assert_eq!( + count(&mut app, fullscreen), + 1, + "a disconnect shows once beside an open approval (fullscreen: {fullscreen})" + ); + + let (mut app, _home) = status_app("local", "fixture-model", Some("high")); + app.apply(Update::Snapshot(Box::default())); + app.apply(Update::Failed("daemon disconnected".into())); + let snapshot = app.snapshot.as_ref().unwrap(); + app.open_prompt(Prompt::Queue(QueuePanel::new(snapshot))); + assert!(matches!(app.prompt, Some(Prompt::Queue(_)))); + assert_eq!( + count(&mut app, fullscreen), + 1, + "a disconnect shows once beside an open queue (fullscreen: {fullscreen})" + ); + } + + for fullscreen in [false, true] { + let (mut app, _home) = status_app("local", "fixture-model", Some("high")); + app.apply(Update::Failed("daemon disconnected".into())); + app.fullscreen = fullscreen; + let (_, bottom, footer) = composer_chrome(&mut app, 100); + assert!(bottom.contains(SLOT), "{bottom}"); + assert!(!footer.contains(SLOT), "{footer}"); + assert_eq!(count(&mut app, fullscreen), 1, "fullscreen: {fullscreen}"); + } + } + #[test] fn both_modes_unify_composer_borders_and_keep_permission_only_on_the_footer() { let (mut app, _home) = status_app("local", "fixture-model", Some("high")); diff --git a/docs/design/cli-commands.md b/docs/design/cli-commands.md index 04a85de122..cb197b9077 100644 --- a/docs/design/cli-commands.md +++ b/docs/design/cli-commands.md @@ -3113,7 +3113,10 @@ Both modes place the model label (with its effort when both fit) on the right si composer's top border, and keep the run status, the status slot (a notice, a required answer or permission, `esc interrupt`, or disconnect), background task count, goal and context information on the left side of the composer's bottom border, leaving only the permission -preset and its shortcut hint on the footer line. +preset and its shortcut hint on the footer line. While a prompt replaces the composer +(permission, question, effort, exit, upgrade, fork, timeline, queue, export or report), +the composer is not drawn, so the footer line also carries the status slot. The slot +is drawn once, on the bottom border or on the footer, never both. ### Submit check warnings diff --git a/docs/design/cli-current-activity.md b/docs/design/cli-current-activity.md index 5072e1c982..3e7354fc7e 100644 --- a/docs/design/cli-current-activity.md +++ b/docs/design/cli-current-activity.md @@ -36,8 +36,10 @@ disconnect), background task count, goal and context usage share the left side of the composer’s bottom border. The place and unread badge continue to share the right side of the bottom border. The model label sits on the right side of the top border, while shell mode keeps the top-border left title. The footer -line below the composer keeps only the permission mode in both modes. Keep the -existing notice slots and +line below the composer keeps only the permission mode in both modes. While a +prompt replaces the composer, the footer also carries the status slot, because +the composer's bottom border is not drawn then. The slot appears once, either on +the bottom border or on the footer. Keep the existing notice slots and [notification and clipping priorities](timeline-ui.md#unread-replies). Shorten the status within its existing space by terminal cell width. Preserve the phase and any known object ahead of optional elapsed text. From 43dae2532852d9f5af0eb0ac24f862bc771402ae Mon Sep 17 00:00:00 2001 From: zjywill Date: Fri, 20 Nov 2026 16:41:10 +0800 Subject: [PATCH 3/8] tui: show notices and disconnects above the footer while a prompt replaces the composer While a prompt replaces the composer, the composer's bottom border is not drawn, so a disconnect, an Enter notice over a stale panel, or a Ctrl+C notice was drawn nowhere in either mode. A replaced composer now shows its notice or disconnect once, on a muted row above the footer. The footer stays permission-only, and the composer shows the slot only when drawn. Also corrects the goal example and Home preview wording in the CLI commands, model configuration and Chinese docs to the unified borders, and tightens two weak assertions (place tail at 60 columns, composer border corners in tmux). Refs #1894 --- crates/dim-cli/README.md | 2 +- crates/dim-cli/src/ui/tui.rs | 152 +++++++++++++++++++--------- docs/design/cli-commands.md | 24 ++--- docs/design/cli-current-activity.md | 6 +- docs/design/model-configuration.md | 2 +- docs/zh/design/cli-commands.md | 19 +--- scripts/tui-tmux/scenarios.mjs | 3 +- 7 files changed, 122 insertions(+), 86 deletions(-) diff --git a/crates/dim-cli/README.md b/crates/dim-cli/README.md index 83b4eb150c..c606f6d2bf 100644 --- a/crates/dim-cli/README.md +++ b/crates/dim-cli/README.md @@ -1152,7 +1152,7 @@ answer text (including its retained streaming tail) · stopped ``` -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, the footer also shows the status slot, once. 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. +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 a row 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. 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. diff --git a/crates/dim-cli/src/ui/tui.rs b/crates/dim-cli/src/ui/tui.rs index 490e9cc7ff..a85d5e70a1 100644 --- a/crates/dim-cli/src/ui/tui.rs +++ b/crates/dim-cli/src/ui/tui.rs @@ -6365,7 +6365,12 @@ impl App { cols.saturating_sub(2 + MARGIN).max(4) }; let margin = " ".repeat(panel_margin); - let composer_rows = if replaced { 0 } else { rows.len() + 2 }; + let notice_row = replaced.then(|| self.replaced_notice(cols)).flatten(); + let composer_rows = if replaced { + usize::from(notice_row.is_some()) + } else { + rows.len() + 2 + }; let panel_rows = if native_selection { size.1 as usize } else { @@ -6509,7 +6514,10 @@ impl App { if let Some(panel) = panel { live.extend(panel.into_iter().map(|row| format!("{margin}{row}"))); } - live.push(self.status_line(cols, replaced)); + if let Some(row) = notice_row { + live.push(row); + } + live.push(self.status_line(cols)); let composer_cursor = ( (box_top + 1 + cursor_row) as u16, (MARGIN + 2 + cursor_col).min(cols.saturating_sub(1)) as u16, @@ -8365,10 +8373,8 @@ impl App { } } - /// The footer line: the permission mode, plus the status slot while a - /// prompt replaces the composer, because the composer's bottom border - /// (which otherwise carries the slot) is not drawn then. - fn status_line(&self, cols: usize, replaced: bool) -> String { + /// The footer line: the permission mode and its shortcut hint. + fn status_line(&self, cols: usize) -> String { use dim_agent_types::PermissionPreset; let p = &self.palette; let preset = self.permission_policy.preset; @@ -8381,23 +8387,25 @@ impl App { let hint = fg(t("(shift+tab to cycle)"), &p.muted); let total = cols.saturating_sub(2); let prefix = format!("{}{permission}", " ".repeat(MARGIN)); - let slot = replaced.then(|| self.slot()).flatten().map(|slot| { - let color = if self.notice.is_some() { - &p.highlight - } else { - &p.muted - }; - fg(&slot, color) - }); - let Some(slot) = slot else { - return clip(&format!("{prefix} {hint}"), total).0; - }; - let with_hint = format!("{prefix} {hint} {slot}"); - if width_of(&with_hint) <= total { - with_hint - } else { - clip(&format!("{prefix} {slot}"), total).0 + clip(&format!("{prefix} {hint}"), total).0 + } + + /// The notice or disconnect line drawn above the footer while a prompt + /// replaces the composer, because the composer's bottom border (which + /// otherwise carries the slot) is not drawn then. Only a notice or a + /// failure is drawn: the prompt itself already names an approval or answer. + fn replaced_notice(&self, cols: usize) -> Option { + if self.notice.is_none() && self.failure.is_none() { + return None; } + let text = self.slot()?; + let color = if self.notice.is_some() { + &self.palette.highlight + } else { + &self.palette.muted + }; + let line = format!("{}{}", " ".repeat(MARGIN), fg(&text, color)); + Some(clip(&line, cols.saturating_sub(2)).0) } } @@ -12122,22 +12130,27 @@ mod tests { } #[test] - fn a_disconnect_stays_visible_once_while_a_prompt_replaces_the_composer() { + fn a_replaced_composer_still_shows_the_disconnect_and_keyboard_notices_once() { use crate::ui::render::panel::strip_escapes; - const SLOT: &str = "Disconnected · draft kept"; - fn count(app: &mut App, fullscreen: bool) -> usize { + const DISCONNECT: &str = "Disconnected · draft kept"; + const RESUME: &str = "Disconnected; draft kept. Exit and resume this Session."; + const INTERRUPT: &str = "Interrupt requested; Ctrl+C again to exit"; + const CTRL_C_AGAIN: &str = "Press Ctrl+C again to exit"; + + fn visible(app: &mut App, fullscreen: bool, text: &str) -> usize { app.fullscreen = fullscreen; app.frame((100, 24)) .live .iter() .map(|row| strip_escapes(row)) - .filter(|row| row.contains(SLOT)) + .filter(|row| row.contains(text)) .count() } - - for fullscreen in [false, true] { - let (mut app, _home) = status_app("local", "fixture-model", Some("high")); - let open = ViewSnapshot { + fn approval_app(fullscreen: bool) -> (App, tempfile::TempDir) { + let (mut app, home) = status_app("local", "fixture-model", Some("high")); + app.fullscreen = fullscreen; + app.apply(Update::Snapshot(Box::new(ViewSnapshot { + session_id: "s1".into(), approvals: vec![crate::model::view::ApprovalView { member: None, request_id: "r1".into(), @@ -12148,37 +12161,45 @@ mod tests { always: None, }], ..ViewSnapshot::default() - }; - app.apply(Update::Snapshot(Box::new(open))); + }))); + assert!( + matches!(app.prompt, Some(Prompt::Permission(_))), + "the approval snapshot opens its permission panel" + ); + (app, home) + } + + for fullscreen in [false, true] { + let (mut app, _home) = approval_app(fullscreen); app.apply(Update::Failed("daemon disconnected".into())); assert!(matches!(app.prompt, Some(Prompt::Permission(_)))); assert_eq!( - count(&mut app, fullscreen), + visible(&mut app, fullscreen, DISCONNECT), 1, "a disconnect shows once beside an open approval (fullscreen: {fullscreen})" ); - let (mut app, _home) = status_app("local", "fixture-model", Some("high")); - app.apply(Update::Snapshot(Box::default())); - app.apply(Update::Failed("daemon disconnected".into())); - let snapshot = app.snapshot.as_ref().unwrap(); - app.open_prompt(Prompt::Queue(QueuePanel::new(snapshot))); - assert!(matches!(app.prompt, Some(Prompt::Queue(_)))); + press(&mut app, KeyCode::Enter); assert_eq!( - count(&mut app, fullscreen), + visible(&mut app, fullscreen, RESUME), 1, - "a disconnect shows once beside an open queue (fullscreen: {fullscreen})" + "Enter over a stale panel shows its notice once (fullscreen: {fullscreen})" ); + assert_eq!(visible(&mut app, fullscreen, DISCONNECT), 0); } for fullscreen in [false, true] { - let (mut app, _home) = status_app("local", "fixture-model", Some("high")); - app.apply(Update::Failed("daemon disconnected".into())); - app.fullscreen = fullscreen; - let (_, bottom, footer) = composer_chrome(&mut app, 100); - assert!(bottom.contains(SLOT), "{bottom}"); - assert!(!footer.contains(SLOT), "{footer}"); - assert_eq!(count(&mut app, fullscreen), 1, "fullscreen: {fullscreen}"); + let (mut app, _home) = approval_app(fullscreen); + let _ = app.handle(InputEvent::Key(crate::ui::terminal::KeyEvent::new( + KeyCode::Char('c'), + Modifiers::CTRL, + ))); + let expected = if fullscreen { CTRL_C_AGAIN } else { INTERRUPT }; + assert_eq!( + visible(&mut app, fullscreen, expected), + 1, + "Ctrl+C over a replaced panel shows its notice once (fullscreen: {fullscreen})" + ); } } @@ -12253,8 +12274,8 @@ mod tests { assert!(bottom.contains("esc interrupt"), "{bottom}"); assert!(bottom.contains("98.3K / 1M"), "{bottom}"); assert!( - bottom.contains('…'), - "place shortens from the left: {bottom}" + bottom.contains("…robe ─╯") && !bottom.contains("dima-probe"), + "place shortens from the left to its tail, without the full workspace path: {bottom}" ); assert!(!footer.contains("esc interrupt"), "{footer}"); assert!(!footer.contains("local / fixture-model"), "{footer}"); @@ -12377,6 +12398,37 @@ mod tests { assert!(narrow_bottom.contains("working…"), "{narrow_bottom}"); assert!(narrow_bottom.contains("esc interrupt"), "{narrow_bottom}"); assert!(narrow_bottom.contains("/lines (1)"), "{narrow_bottom}"); + + // A real approval opens its panel, which replaces the composer. A + // disconnect while it is open is drawn once, on the live rows. + app.apply(Update::Snapshot(Box::new(ViewSnapshot { + session_id: "s1".into(), + approvals: vec![ApprovalView { + member: None, + branch_id: "main".into(), + request_id: "req-2".into(), + tool_name: "exec".into(), + reason: "run".into(), + tool_input: serde_json::json!({"command": "echo hi"}), + always: None, + }], + ..ViewSnapshot::default() + }))); + assert!(matches!(app.prompt, Some(Prompt::Permission(_)))); + app.apply(Update::Failed("daemon disconnected".into())); + let live: Vec = app + .frame((100, 24)) + .live + .iter() + .map(|row| crate::ui::render::panel::strip_escapes(row)) + .collect(); + assert_eq!( + live.iter() + .filter(|row| row.contains("Disconnected · draft kept")) + .count(), + 1, + "{live:?}" + ); } impl SessionPort for Recorder { diff --git a/docs/design/cli-commands.md b/docs/design/cli-commands.md index cb197b9077..a1fa8a2aa9 100644 --- a/docs/design/cli-commands.md +++ b/docs/design/cli-commands.md @@ -677,22 +677,14 @@ prints two lines: usage, then the no-goal notice. The line client and both terminal UI modes print these lines; in the terminal UI they are one report in the transcript, so earlier reports stay readable above later ones. The status area carries one short element while the shown line follows a goal, and nothing for a completed, -blocked or cleared one: +blocked or cleared one. Both modes draw it the same way: on the composer's bottom border, beside +the run status and context usage, with the place on its right: ```text - ╭──────────────────────────────────────────────────────────────────────────────╮ + ╭────────────────────────────────────────────────────── local / fixture-model ─╮ │ › _ │ - ╰────────────────────────────── ⑂ main ▸ child work · after message 0 ─────────╯ - ⏵⏵ Workspace write (shift+tab to cycle) ◎ goal active 1.8K / 256K -``` - -Fullscreen draws the same element in the composer's bottom border, beside the run status: - -```text - ╭──────────────────────────────────────────────────────────────────────────────╮ - │ › _ │ - ╰──── ◎ goal paused 1.8K / 256K ────────────────── ● main · after message 4 ─╯ - ⏵⏵ Full access (shift+tab to cycle) + ╰─ ◎ goal active 1.8K / 256K ───────── ⑂ main ▸ child work · after message 0 ─╯ + ⏵⏵ Workspace write (shift+tab to cycle) ``` ## Loop @@ -1490,7 +1482,7 @@ Enter also writes the default a new Session in this folder reads ([provider mana Bare `/effort` and `/reasoning` open the current model's inline effort picker in both TUI modes; explicit-value forms and the line client keep their command behavior. At Home the -picker and the explicit-value forms act on the footer's preview, the model the first +picker and the explicit-value forms act on the top border's preview, the model the first message's Session adopts. The selection contract is owned by [model configuration](model-configuration.md#scrollback-interaction). @@ -3115,8 +3107,8 @@ or permission, `esc interrupt`, or disconnect), background task count, goal and information on the left side of the composer's bottom border, leaving only the permission preset and its shortcut hint on the footer line. While a prompt replaces the composer (permission, question, effort, exit, upgrade, fork, timeline, queue, export or report), -the composer is not drawn, so the footer line also carries the status slot. The slot -is drawn once, on the bottom border or on the footer, never both. +the composer is not drawn, so a notice or the disconnect state is drawn once on a row +just above the footer, and the footer stays permission-only. ### Submit check warnings diff --git a/docs/design/cli-current-activity.md b/docs/design/cli-current-activity.md index 3e7354fc7e..0066e06c70 100644 --- a/docs/design/cli-current-activity.md +++ b/docs/design/cli-current-activity.md @@ -37,9 +37,9 @@ of the composer’s bottom border. The place and unread badge continue to share the right side of the bottom border. The model label sits on the right side of the top border, while shell mode keeps the top-border left title. The footer line below the composer keeps only the permission mode in both modes. While a -prompt replaces the composer, the footer also carries the status slot, because -the composer's bottom border is not drawn then. The slot appears once, either on -the bottom border or on the footer. Keep the existing notice slots and +prompt replaces the composer, the composer is not drawn, so a notice or the +disconnect state is drawn once on a row above the footer. Keep the existing +notice slots and [notification and clipping priorities](timeline-ui.md#unread-replies). Shorten the status within its existing space by terminal cell width. Preserve the phase and any known object ahead of optional elapsed text. diff --git a/docs/design/model-configuration.md b/docs/design/model-configuration.md index 0feb35f77d..62d93853b9 100644 --- a/docs/design/model-configuration.md +++ b/docs/design/model-configuration.md @@ -578,7 +578,7 @@ and show supported choices from the existing `provider.catalog` response, withou mutation or a new query method. Bare `/agent` uses existing `agent.list` IDs, names and descriptions; selection uses an exact ID. Empty/unavailable choices are explicit. -At Home there is no adopted model yet: the footer's preview is the model the first +At Home there is no adopted model yet: the top border's preview is the model the first message's Session adopts, so the same commands act on it. Bare `/effort` and `/fast` list that model's advertised choices, and a value is held for the Session the first message creates instead of writing the shown one. The preview reported the model's diff --git a/docs/zh/design/cli-commands.md b/docs/zh/design/cli-commands.md index 6625f64962..a0a6918680 100644 --- a/docs/zh/design/cli-commands.md +++ b/docs/zh/design/cli-commands.md @@ -355,22 +355,13 @@ Goal cleared on main. 清除目标时只打印一行确认;在没有目标的线上提交空参数 `/goal` 则打印两行:用法和没有目标的提示。 行客户端和两种终端 UI 模式都打印这些行;在终端 UI 里它们是一段报告,因此更早的报告仍能在上方读到。 -当前显示线跟随目标(进行中或暂停)时,状态区带一个短元素,完成、受阻或已清除的目标没有: +当前显示线跟随目标(进行中或暂停)时,状态区带一个短元素,完成、受阻或已清除的目标没有。两种模式的画法相同:放在输入框下边框上,与运行状态、上下文用量并列,地点在右侧: ```text - ╭──────────────────────────────────────────────────────────────────────────────╮ + ╭────────────────────────────────────────────────────── local / fixture-model ─╮ │ › _ │ - ╰────────────────────────────── ⑂ main ▸ child work · after message 0 ─────────╯ - ⏵⏵ Workspace write (Shift+Tab 切换) ◎ goal active 1.8K / 256K -``` - -fullscreen 把同一元素画在输入框的下边框,位于运行状态旁: - -```text - ╭──────────────────────────────────────────────────────────────────────────────╮ - │ › _ │ - ╰──── ◎ goal paused 1.8K / 256K ────────────────── ● main · after message 4 ─╯ - ⏵⏵ Full access (Shift+Tab 切换) + ╰─ ◎ goal active 1.8K / 256K ───────── ⑂ main ▸ child work · after message 0 ─╯ + ⏵⏵ Workspace write (Shift+Tab 切换) ``` ## Loop @@ -1872,7 +1863,7 @@ Assistant: ... 按键行为见 [`/permissions`](#permissions)。页脚不提交到正文历史。 两种模式都把模型标签(放得下时连同推理强度)放在输入框上边框右侧,把运行状态、状态槽(通知、需要回答 或审批、`esc interrupt` 或断连)、后台任务数、目标与上下文信息放在输入框下边框左侧;页脚行只保留 -权限预设及其快捷键提示。 +权限预设及其快捷键提示。输入框被弹窗替换时,通知或断连状态在页脚上方的一行绘制一次,页脚仍只保留权限。 ### 提交检查的警告 diff --git a/scripts/tui-tmux/scenarios.mjs b/scripts/tui-tmux/scenarios.mjs index fd250e3adf..87e3e55530 100644 --- a/scripts/tui-tmux/scenarios.mjs +++ b/scripts/tui-tmux/scenarios.mjs @@ -918,7 +918,8 @@ const scenarios = [ const chrome = composerChrome(terminal); const widest = Math.max(0, ...chrome.lines.map((line) => line.length)); if ( - widest <= 60 && + chrome.top.trimEnd().endsWith('╮') && + chrome.bottom.trimEnd().endsWith('╯') && chrome.top.includes('local / fixture-model') && chrome.bottom.includes('thinking…') && chrome.bottom.includes('esc interrupt') && From 7bdf5aa113bc3643156f17a6453b0e8fc8cb7674 Mon Sep 17 00:00:00 2001 From: zjywill Date: Fri, 20 Nov 2026 17:00:25 +0800 Subject: [PATCH 4/8] tui: keep the stop shortcut and slot on the border before a retry reason The bottom border clipped the whole status corner from the right, so a long retry reason pushed esc interrupt off the border. The corner now fits its parts in order: full run status, essential run status (the phase without the reason), then the slot alone beside the phase; the optional parts go first, and the slot always stays whole. The same rule applies in fullscreen, which shares this path. A replaced composer's notice or disconnect wraps onto rows instead of being clipped, so a narrow terminal keeps the whole text. Refs #1894 --- crates/dim-cli/src/ui/tui.rs | 221 ++++++++++++++++++++++++++++------- 1 file changed, 179 insertions(+), 42 deletions(-) diff --git a/crates/dim-cli/src/ui/tui.rs b/crates/dim-cli/src/ui/tui.rs index a85d5e70a1..8af564798e 100644 --- a/crates/dim-cli/src/ui/tui.rs +++ b/crates/dim-cli/src/ui/tui.rs @@ -6158,10 +6158,14 @@ impl App { ) .max(1); live.push(String::new()); + // The run status as (full, essential): the full text carries the + // retry reason, and the essential one keeps only the phase, so the + // border can drop the reason before it cuts the slot. let status = (self.prompt.is_none() && self.running()).then(|| { let started = self.run_started.unwrap_or_else(Instant::now); let elapsed = started.elapsed(); let beat = (elapsed.as_millis() / PULSE.as_millis()) as usize; + let pulse = PULSE_FRAMES[beat % PULSE_FRAMES.len()]; let retry = self .snapshot .as_ref() @@ -6170,18 +6174,17 @@ impl App { let seconds = crate::projection::retry_seconds(retry.retry_at_ms); let reason = crate::projection::failure_phrase(retry.kind, retry.reason.as_deref()); if seconds == 0 { - return format!( - "{} {}", - PULSE_FRAMES[beat % PULSE_FRAMES.len()], + let full = format!( + "{pulse} {}", tf( "Waiting for the provider · {reason} · Esc stops", &[("reason", &reason)] ) ); + return (full, format!("{pulse} {}", t("Waiting for the provider"))); } - return format!( - "{} {}", - PULSE_FRAMES[beat % PULSE_FRAMES.len()], + let full = format!( + "{pulse} {}", tf( "Retrying {attempt}/{max} in {seconds} s · {reason} · Esc stops", &[ @@ -6192,6 +6195,18 @@ impl App { ] ) ); + let essential = format!( + "{pulse} {}", + tf( + "Retrying {attempt}/{max} in {seconds} s", + &[ + ("attempt", &retry.attempt.to_string()), + ("max", &retry.max_attempts.to_string()), + ("seconds", &seconds.to_string()), + ] + ) + ); + return (full, essential); } let thinking = self.snapshot.as_ref().is_some_and(|snapshot| { snapshot.rows.iter().any(|row| { @@ -6203,11 +6218,11 @@ impl App { } else { "working… {elapsed}" }; - format!( - "{} {}", - PULSE_FRAMES[beat % PULSE_FRAMES.len()], + let text = format!( + "{pulse} {}", tf(label, &[("elapsed", &format_elapsed(elapsed))]) - ) + ); + (text.clone(), text) }); let inner = cols.saturating_sub(MARGIN + 6).max(1); let shell = self.composer.shell(); @@ -6309,7 +6324,10 @@ impl App { let end = MARGIN + outer - 3; frame.model_label = Some((box_top, end - width_of(model)..end)); } - let docked = self.dock_status(status.as_deref()).and_then(|text| { + let run = status + .as_ref() + .map(|(full, essential)| (full.as_str(), essential.as_str())); + let docked = self.dock_status(run, max_border).and_then(|text| { if width_of(&text) <= max_border { return Some(text); } @@ -6365,9 +6383,13 @@ impl App { cols.saturating_sub(2 + MARGIN).max(4) }; let margin = " ".repeat(panel_margin); - let notice_row = replaced.then(|| self.replaced_notice(cols)).flatten(); + let notice_rows = if replaced { + self.replaced_notice(cols) + } else { + Vec::new() + }; let composer_rows = if replaced { - usize::from(notice_row.is_some()) + notice_rows.len() } else { rows.len() + 2 }; @@ -6514,9 +6536,7 @@ impl App { if let Some(panel) = panel { live.extend(panel.into_iter().map(|row| format!("{margin}{row}"))); } - if let Some(row) = notice_row { - live.push(row); - } + live.extend(notice_rows); live.push(self.status_line(cols)); let composer_cursor = ( (box_top + 1 + cursor_row) as u16, @@ -8305,28 +8325,27 @@ impl App { } } - /// The composer's bottom-left border label, the status corner: the run - /// status, the slot (a notice in the highlight colour), background task - /// count, goal and context use. - fn dock_status(&self, run: Option<&str>) -> Option { + /// The composer's bottom-left status corner: the run status, the slot (a + /// notice in the highlight colour), background task count, goal and + /// context use, fitted to `budget` cells. The slot always stays whole. + /// The optional parts go first, then the run status's reason; the corner + /// falls back to the phase beside the slot, and to the slot alone. + fn dock_status(&self, run: Option<(&str, &str)>, budget: usize) -> Option { let p = &self.palette; - let mut parts: Vec = Vec::new(); - if let Some(run) = run { - parts.push(fg(run, &p.activity)); - } - if let Some(slot) = self.slot() { + let slot = self.slot().map(|slot| { let color = if self.notice.is_some() { &p.highlight } else { &p.muted }; - parts.push(fg(&slot, color)); - } + fg(&slot, color) + }); + let mut optional: Vec = Vec::new(); if let Some(background) = self.background_label() { - parts.push(fg(&background, &p.muted)); + optional.push(fg(&background, &p.muted)); } if let Some(goal) = self.goal_label() { - parts.push(fg(goal, &p.muted)); + optional.push(fg(goal, &p.muted)); } if let Some(context) = self.context_label() { let color = if self.context_near() { @@ -8334,9 +8353,30 @@ impl App { } else { &p.muted }; - parts.push(fg(&context, color)); + optional.push(fg(&context, color)); } - (!parts.is_empty()).then(|| parts.join(" ")) + let join = |run: Option<&str>, optional: &[String]| { + let mut parts: Vec = Vec::new(); + if let Some(run) = run { + parts.push(fg(run, &p.activity)); + } + parts.extend(slot.clone()); + parts.extend(optional.iter().cloned()); + (!parts.is_empty()).then(|| parts.join(" ")) + }; + let (full, essential) = run.map_or((None, None), |(full, essential)| { + (Some(full), Some(essential)) + }); + [ + join(full, &optional), + join(essential, &optional), + join(essential, &[]), + join(None, &[]), + ] + .into_iter() + .flatten() + .find(|text| width_of(text) <= budget) + .or_else(|| join(essential, &[])) } /// The composer's bottom-right label, built to fit the cells the border @@ -8390,22 +8430,28 @@ impl App { clip(&format!("{prefix} {hint}"), total).0 } - /// The notice or disconnect line drawn above the footer while a prompt - /// replaces the composer, because the composer's bottom border (which - /// otherwise carries the slot) is not drawn then. Only a notice or a - /// failure is drawn: the prompt itself already names an approval or answer. - fn replaced_notice(&self, cols: usize) -> Option { + /// The notice or disconnect drawn above the footer while a prompt replaces + /// the composer, because the composer's bottom border (which otherwise + /// carries the slot) is not drawn then. Only a notice or a failure is + /// drawn: the prompt itself already names an approval or answer. The text + /// wraps onto as many rows as it needs, so the slot is never cut. + fn replaced_notice(&self, cols: usize) -> Vec { if self.notice.is_none() && self.failure.is_none() { - return None; + return Vec::new(); } - let text = self.slot()?; + let Some(text) = self.slot() else { + return Vec::new(); + }; let color = if self.notice.is_some() { &self.palette.highlight } else { &self.palette.muted }; - let line = format!("{}{}", " ".repeat(MARGIN), fg(&text, color)); - Some(clip(&line, cols.saturating_sub(2)).0) + let width = cols.saturating_sub(MARGIN + 1).max(1); + wrap_words(&text, width) + .into_iter() + .map(|row| format!("{}{}", " ".repeat(MARGIN), fg(&row, color))) + .collect() } } @@ -12203,6 +12249,94 @@ mod tests { } } + #[test] + fn a_replaced_composer_keeps_a_narrow_notice_whole() { + use crate::ui::render::panel::strip_escapes; + const DISCONNECT: &str = "Disconnected · draft kept"; + const RESUME: &str = "Disconnected; draft kept. Exit and resume this Session."; + fn rows(app: &mut App, fullscreen: bool, cols: u16) -> Vec { + app.fullscreen = fullscreen; + app.frame((cols, 24)) + .live + .iter() + .map(|row| strip_escapes(row).trim().to_owned()) + .collect() + } + for fullscreen in [false, true] { + let (mut app, _home) = status_app("local", "fixture-model", Some("high")); + app.apply(Update::Snapshot(Box::new(ViewSnapshot { + session_id: "s1".into(), + approvals: vec![crate::model::view::ApprovalView { + member: None, + request_id: "r1".into(), + branch_id: "main".into(), + reason: "shell command".into(), + tool_name: "exec".into(), + tool_input: serde_json::Value::Null, + always: None, + }], + ..ViewSnapshot::default() + }))); + app.apply(Update::Failed("daemon disconnected".into())); + let shown = rows(&mut app, fullscreen, 100); + assert_eq!( + shown.iter().filter(|row| row.contains(DISCONNECT)).count(), + 1, + "fullscreen: {fullscreen}" + ); + + press(&mut app, KeyCode::Enter); + let narrow = rows(&mut app, fullscreen, 32); + let flat = narrow.join(" "); + assert!( + flat.contains(RESUME), + "the 32-column notice keeps its whole text (fullscreen: {fullscreen}):\n{}", + narrow.join("\n") + ); + } + } + + #[test] + fn a_retry_keeps_the_stop_shortcut_on_the_border_before_its_reason() { + for fullscreen in [false, true] { + let (mut app, _home) = status_app("local", "fixture-model", Some("high")); + app.fullscreen = fullscreen; + app.apply(Update::Snapshot(Box::new(ViewSnapshot { + session_id: "s1".into(), + running: true, + retry: Some(crate::model::view::RetryView { + attempt: 2, + max_attempts: 8, + retry_at_ms: retry_at(60_000), + kind: dim_agent_types::ModelFailureKind::ServerError, + reason: Some( + "The provider reported a server error: The server is overloaded and cannot take more requests right now" + .into(), + ), + }), + ..ViewSnapshot::default() + }))); + for cols in [100u16, 60, 48, 40] { + let (_, bottom, footer) = composer_chrome(&mut app, cols); + assert!( + bottom.contains("esc interrupt"), + "{cols} columns, fullscreen {fullscreen}: the stop shortcut is on the border: {bottom}" + ); + assert!(!footer.contains("esc interrupt"), "{cols}: {footer}"); + assert!( + !bottom.contains("server error"), + "{cols} columns: the long reason is dropped before the slot: {bottom}" + ); + if cols >= 48 { + assert!( + bottom.contains("Retrying 2/8 in"), + "{cols} columns keeps the phase beside the slot: {bottom}" + ); + } + } + } + } + #[test] fn both_modes_unify_composer_borders_and_keep_permission_only_on_the_footer() { let (mut app, _home) = status_app("local", "fixture-model", Some("high")); @@ -12280,10 +12414,12 @@ mod tests { assert!(!footer.contains("esc interrupt"), "{footer}"); assert!(!footer.contains("local / fixture-model"), "{footer}"); - // Very narrow (24 cols): status keeps its phase ahead of elapsed/slot; model drops. + // Very narrow (24 cols): the slot stays whole and the phase drops + // when both cannot fit; the model label drops too. let (top, bottom, _) = composer_chrome(&mut app, 24); assert!(!top.contains("local / fixture-model"), "{top}"); - assert!(bottom.contains("thinking…"), "{bottom}"); + assert!(bottom.contains("esc interrupt"), "{bottom}"); + assert!(!bottom.contains("thinking…"), "{bottom}"); } } @@ -12354,6 +12490,7 @@ mod tests { let (top, bottom, footer) = composer_chrome(&mut app, cols); assert!(!top.contains("Retrying"), "{cols}: {top}"); assert!(bottom.contains("Retrying 2/8 in"), "{cols}: {bottom}"); + assert!(bottom.contains("esc interrupt"), "{cols}: {bottom}"); assert!(!footer.contains("Retrying"), "{cols}: {footer}"); } From 18c5edf17390536692ac2018a35d98fc50453c82 Mon Sep 17 00:00:00 2001 From: zjywill Date: Fri, 20 Nov 2026 17:22:18 +0800 Subject: [PATCH 5/8] tui: shorten the bottom corner by dropping optional parts before it vanishes When no run status and no slot are shown, the corner had only the whole optional string as a candidate, so at 60 columns it vanished when the background task count, goal and context did not fit together. The corner now tries the run status and then fewer and fewer optional parts (context first, then goal, then background tasks), then the optional parts without a run status, and the slot alone. The slot always stays whole; if even the first optional part does not fit, it is clipped rather than dropped. Refs #1894 --- crates/dim-cli/README.md | 2 +- crates/dim-cli/src/ui/tui.rs | 63 ++++++++++++++++++++++++----- docs/design/cli-commands.md | 7 +++- docs/design/cli-current-activity.md | 2 +- docs/zh/design/cli-commands.md | 2 +- 5 files changed, 61 insertions(+), 15 deletions(-) diff --git a/crates/dim-cli/README.md b/crates/dim-cli/README.md index c606f6d2bf..46c524a69d 100644 --- a/crates/dim-cli/README.md +++ b/crates/dim-cli/README.md @@ -1152,7 +1152,7 @@ answer text (including its retained streaming tail) · stopped ``` -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 a row 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. +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. 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. diff --git a/crates/dim-cli/src/ui/tui.rs b/crates/dim-cli/src/ui/tui.rs index 8af564798e..b02d344766 100644 --- a/crates/dim-cli/src/ui/tui.rs +++ b/crates/dim-cli/src/ui/tui.rs @@ -8367,16 +8367,23 @@ impl App { let (full, essential) = run.map_or((None, None), |(full, essential)| { (Some(full), Some(essential)) }); - [ - join(full, &optional), - join(essential, &optional), - join(essential, &[]), - join(None, &[]), - ] - .into_iter() - .flatten() - .find(|text| width_of(text) <= budget) - .or_else(|| join(essential, &[])) + // Candidates in priority order: the full run status with every + // optional part, then the essential phase with fewer and fewer + // optional parts (the last optional part is the first to go), then + // the optional parts without a run status, and the slot alone. + let mut candidates = vec![join(full, &optional)]; + for keep in (0..=optional.len()).rev() { + candidates.push(join(essential, &optional[..keep])); + } + for keep in (0..=optional.len()).rev() { + candidates.push(join(None, &optional[..keep])); + } + candidates + .into_iter() + .flatten() + .find(|text| width_of(text) <= budget) + .or_else(|| join(essential, &[])) + .or_else(|| join(None, &optional[..optional.len().min(1)])) } /// The composer's bottom-right label, built to fit the cells the border @@ -12296,6 +12303,42 @@ mod tests { } } + #[test] + fn a_bottom_corner_without_run_or_slot_drops_its_lowest_parts_first() { + for fullscreen in [false, true] { + let (mut app, _home) = status_app("local", "fixture-model", Some("high")); + app.fullscreen = fullscreen; + app.context = Some(crate::model::session::ContextReading { + input: 98_300, + window: 256_000, + threshold: 900_000, + }); + app.apply(Update::Snapshot(Box::new(ViewSnapshot { + session_id: "s1".into(), + tasks: vec![background_task("t1", "cargo build")], + goal: Some(dim_agent_types::GoalView { + objective: "ship".into(), + status: dim_agent_types::GoalViewStatus::Active, + evaluator: false, + }), + ..ViewSnapshot::default() + }))); + + // 60 columns: all three parts need 53 cells, the budget is 51, so + // the context (the lowest part) goes and the other two stay. + let (_, bottom, _) = composer_chrome(&mut app, 60); + assert!(bottom.contains("1 in background · /tasks"), "{bottom}"); + assert!(bottom.contains("◎ goal active"), "{bottom}"); + assert!(!bottom.contains("98.3K"), "{bottom}"); + + // 40 columns: only the task count fits beside the corner's border. + let (_, bottom, _) = composer_chrome(&mut app, 40); + assert!(bottom.contains("1 in background · /tasks"), "{bottom}"); + assert!(!bottom.contains("goal active"), "{bottom}"); + assert!(!bottom.contains("98.3K"), "{bottom}"); + } + } + #[test] fn a_retry_keeps_the_stop_shortcut_on_the_border_before_its_reason() { for fullscreen in [false, true] { diff --git a/docs/design/cli-commands.md b/docs/design/cli-commands.md index a1fa8a2aa9..333fb0048f 100644 --- a/docs/design/cli-commands.md +++ b/docs/design/cli-commands.md @@ -3105,9 +3105,12 @@ Both modes place the model label (with its effort when both fit) on the right si composer's top border, and keep the run status, the status slot (a notice, a required answer or permission, `esc interrupt`, or disconnect), background task count, goal and context information on the left side of the composer's bottom border, leaving only the permission -preset and its shortcut hint on the footer line. While a prompt replaces the composer +preset and its shortcut hint on the footer line. When the corner is too narrow, its parts +go in this order: first the context usage, then the goal, then the background task count, +while the run status head and the slot stay whole when the width allows it; the retry +reason goes before the optional parts. While a prompt replaces the composer (permission, question, effort, exit, upgrade, fork, timeline, queue, export or report), -the composer is not drawn, so a notice or the disconnect state is drawn once on a row +the composer is not drawn, so a notice or the disconnect state is drawn once, on the rows just above the footer, and the footer stays permission-only. ### Submit check warnings diff --git a/docs/design/cli-current-activity.md b/docs/design/cli-current-activity.md index 0066e06c70..57336eb7c5 100644 --- a/docs/design/cli-current-activity.md +++ b/docs/design/cli-current-activity.md @@ -38,7 +38,7 @@ the right side of the bottom border. The model label sits on the right side of the top border, while shell mode keeps the top-border left title. The footer line below the composer keeps only the permission mode in both modes. While a prompt replaces the composer, the composer is not drawn, so a notice or the -disconnect state is drawn once on a row above the footer. Keep the existing +disconnect state is drawn once, on the rows above the footer. Keep the existing notice slots and [notification and clipping priorities](timeline-ui.md#unread-replies). Shorten the status within its existing space by terminal cell width. Preserve diff --git a/docs/zh/design/cli-commands.md b/docs/zh/design/cli-commands.md index a0a6918680..b161d524b8 100644 --- a/docs/zh/design/cli-commands.md +++ b/docs/zh/design/cli-commands.md @@ -1863,7 +1863,7 @@ Assistant: ... 按键行为见 [`/permissions`](#permissions)。页脚不提交到正文历史。 两种模式都把模型标签(放得下时连同推理强度)放在输入框上边框右侧,把运行状态、状态槽(通知、需要回答 或审批、`esc interrupt` 或断连)、后台任务数、目标与上下文信息放在输入框下边框左侧;页脚行只保留 -权限预设及其快捷键提示。输入框被弹窗替换时,通知或断连状态在页脚上方的一行绘制一次,页脚仍只保留权限。 +权限预设及其快捷键提示。下边框太窄时,各部分按此顺序让出:先去掉上下文用量,再去掉目标,最后去掉后台任务数;在宽度允许时,运行状态的主体与状态槽保持完整;重试原因先于这些可选部分让出。输入框被弹窗替换时,通知或断连状态在页脚上方的若干行绘制一次,页脚仍只保留权限。 ### 提交检查的警告 From c1bc3c6fd725c08197f8e3e656651eb59905f21a Mon Sep 17 00:00:00 2001 From: zjywill Date: Fri, 20 Nov 2026 17:25:40 +0800 Subject: [PATCH 6/8] tui: document that the corner slot is clipped only when it alone is too wide The bottom corner keeps the slot whole when it fits the border and clips it from its end only when the slot alone is wider. The dock_status comment and the CLI commands design (English and Chinese) now say so, and the narrow corner test asserts a 40-column notice starts at the corner's left edge with nothing beside it. Refs #1894 --- crates/dim-cli/src/ui/tui.rs | 21 ++++++++++++++++++--- docs/design/cli-commands.md | 7 ++++--- docs/zh/design/cli-commands.md | 2 +- 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/crates/dim-cli/src/ui/tui.rs b/crates/dim-cli/src/ui/tui.rs index b02d344766..91bffaca61 100644 --- a/crates/dim-cli/src/ui/tui.rs +++ b/crates/dim-cli/src/ui/tui.rs @@ -8327,9 +8327,10 @@ impl App { /// The composer's bottom-left status corner: the run status, the slot (a /// notice in the highlight colour), background task count, goal and - /// context use, fitted to `budget` cells. The slot always stays whole. - /// The optional parts go first, then the run status's reason; the corner - /// falls back to the phase beside the slot, and to the slot alone. + /// context use, fitted to `budget` cells. The slot outranks every other + /// part and is kept whole when it fits the border; the caller clips it + /// from its end only when the slot alone is wider than the border. The + /// optional parts go first, then the run status's reason. fn dock_status(&self, run: Option<(&str, &str)>, budget: usize) -> Option { let p = &self.palette; let slot = self.slot().map(|slot| { @@ -12336,6 +12337,20 @@ mod tests { assert!(bottom.contains("1 in background · /tasks"), "{bottom}"); assert!(!bottom.contains("goal active"), "{bottom}"); assert!(!bottom.contains("98.3K"), "{bottom}"); + + // A slot wider than the border is clipped from its end. It starts at + // the corner's left edge, and no optional part or place is drawn beside it. + app.set_notice("Interrupt requested; Ctrl+C again to exit"); + let (_, bottom, _) = composer_chrome(&mut app, 40); + assert!( + bottom.starts_with(" ╰─ Interrupt requested; Ctrl+C aga"), + "the slot is clipped from its end at the left edge: {bottom}" + ); + assert!(!bottom.contains("exit"), "{bottom}"); + assert!(!bottom.contains("background"), "{bottom}"); + assert!(!bottom.contains("goal"), "{bottom}"); + assert!(!bottom.contains("dima-probe"), "{bottom}"); + app.notice = None; } } diff --git a/docs/design/cli-commands.md b/docs/design/cli-commands.md index 333fb0048f..e0f3f02dc8 100644 --- a/docs/design/cli-commands.md +++ b/docs/design/cli-commands.md @@ -3106,9 +3106,10 @@ composer's top border, and keep the run status, the status slot (a notice, a req or permission, `esc interrupt`, or disconnect), background task count, goal and context information on the left side of the composer's bottom border, leaving only the permission preset and its shortcut hint on the footer line. When the corner is too narrow, its parts -go in this order: first the context usage, then the goal, then the background task count, -while the run status head and the slot stay whole when the width allows it; the retry -reason goes before the optional parts. While a prompt replaces the composer +go in this order: first the context usage, then the goal, then the background task count. +The retry reason and the run status head go before the optional parts. The slot outranks +every other part: it is kept whole when it fits the border, and clipped from its end only +when the slot alone is wider than the border. While a prompt replaces the composer (permission, question, effort, exit, upgrade, fork, timeline, queue, export or report), the composer is not drawn, so a notice or the disconnect state is drawn once, on the rows just above the footer, and the footer stays permission-only. diff --git a/docs/zh/design/cli-commands.md b/docs/zh/design/cli-commands.md index b161d524b8..4f525bca35 100644 --- a/docs/zh/design/cli-commands.md +++ b/docs/zh/design/cli-commands.md @@ -1863,7 +1863,7 @@ Assistant: ... 按键行为见 [`/permissions`](#permissions)。页脚不提交到正文历史。 两种模式都把模型标签(放得下时连同推理强度)放在输入框上边框右侧,把运行状态、状态槽(通知、需要回答 或审批、`esc interrupt` 或断连)、后台任务数、目标与上下文信息放在输入框下边框左侧;页脚行只保留 -权限预设及其快捷键提示。下边框太窄时,各部分按此顺序让出:先去掉上下文用量,再去掉目标,最后去掉后台任务数;在宽度允许时,运行状态的主体与状态槽保持完整;重试原因先于这些可选部分让出。输入框被弹窗替换时,通知或断连状态在页脚上方的若干行绘制一次,页脚仍只保留权限。 +权限预设及其快捷键提示。下边框太窄时,各部分按此顺序让出:先去掉上下文用量,再去掉目标,最后去掉后台任务数;重试原因与运行状态的主体先于这些可选部分让出。状态槽优先于其他所有部分:只要能放进边框就保持完整,只有状态槽本身比边框还宽时才从末尾截断。输入框被弹窗替换时,通知或断连状态在页脚上方的若干行绘制一次,页脚仍只保留权限。 ### 提交检查的警告 From 2dca1750c61819ca9d791b53530202325b15c702 Mon Sep 17 00:00:00 2001 From: zjywill Date: Fri, 20 Nov 2026 17:43:53 +0800 Subject: [PATCH 7/8] tui: show a wider slot alone when nothing fits the bottom corner When the slot alone was wider than the border, the fallback put the phase beside it, and the outer clip cut the slot from its end. The fallback now returns the slot alone, so the notice leads the corner and the outer clip shortens it. Without a slot the phase and the first optional part still fall back in that order. Refs #1894 --- crates/dim-cli/src/ui/tui.rs | 48 ++++++++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/crates/dim-cli/src/ui/tui.rs b/crates/dim-cli/src/ui/tui.rs index 91bffaca61..f5ced35d2b 100644 --- a/crates/dim-cli/src/ui/tui.rs +++ b/crates/dim-cli/src/ui/tui.rs @@ -8383,8 +8383,13 @@ impl App { .into_iter() .flatten() .find(|text| width_of(text) <= budget) - .or_else(|| join(essential, &[])) - .or_else(|| join(None, &optional[..optional.len().min(1)])) + .or_else(|| { + if slot.is_some() { + join(None, &[]) + } else { + join(essential, &[]).or_else(|| join(None, &optional[..optional.len().min(1)])) + } + }) } /// The composer's bottom-right label, built to fit the cells the border @@ -12304,6 +12309,45 @@ mod tests { } } + #[test] + fn a_slot_wider_than_the_border_is_not_replaced_by_the_phase() { + for fullscreen in [false, true] { + let (mut app, _home) = status_app("local", "fixture-model", Some("high")); + app.fullscreen = fullscreen; + app.apply(Update::Snapshot(Box::new(ViewSnapshot { + session_id: "s1".into(), + running: true, + retry: Some(crate::model::view::RetryView { + attempt: 2, + max_attempts: 8, + retry_at_ms: retry_at(60_000), + kind: dim_agent_types::ModelFailureKind::ServerError, + reason: Some("The provider reported a server error".into()), + }), + ..ViewSnapshot::default() + }))); + app.set_notice("Interrupt requested; Ctrl+C again to exit"); + let (_, bottom, _) = composer_chrome(&mut app, 40); + assert!( + bottom.starts_with(" ╰─ Interrupt requested; Ctrl+C aga"), + "fullscreen {fullscreen}: the notice leads the corner: {bottom}" + ); + assert!( + !bottom.contains("Retrying"), + "fullscreen {fullscreen}: {bottom}" + ); + assert!( + !bottom.contains("server error"), + "fullscreen {fullscreen}: {bottom}" + ); + assert!( + !bottom.contains("esc interrupt"), + "fullscreen {fullscreen}: {bottom}" + ); + app.notice = None; + } + } + #[test] fn a_bottom_corner_without_run_or_slot_drops_its_lowest_parts_first() { for fullscreen in [false, true] { From e54529a7f7d497b82eb176914f3cebfb24dff3eb Mon Sep 17 00:00:00 2001 From: zjywill Date: Fri, 20 Nov 2026 17:50:53 +0800 Subject: [PATCH 8/8] tui: state the bottom corner's candidate order where the code applies it The corner drops the retry reason first, then the phase, then optional parts (context, goal, background tasks). The comment and the design docs described the order incorrectly. The comment, the English and Chinese CLI commands design now list the real order. A test covers the running retry with a long notice leading the corner, and that at 40 columns the goal stays when the phase does not fit. Refs #1894 --- crates/dim-cli/src/ui/tui.rs | 82 ++++++++++++++++++++++++++++++++-- docs/design/cli-commands.md | 12 ++--- docs/zh/design/cli-commands.md | 2 +- 3 files changed, 86 insertions(+), 10 deletions(-) diff --git a/crates/dim-cli/src/ui/tui.rs b/crates/dim-cli/src/ui/tui.rs index f5ced35d2b..e3d993ce93 100644 --- a/crates/dim-cli/src/ui/tui.rs +++ b/crates/dim-cli/src/ui/tui.rs @@ -8327,10 +8327,19 @@ impl App { /// The composer's bottom-left status corner: the run status, the slot (a /// notice in the highlight colour), background task count, goal and - /// context use, fitted to `budget` cells. The slot outranks every other - /// part and is kept whole when it fits the border; the caller clips it - /// from its end only when the slot alone is wider than the border. The - /// optional parts go first, then the run status's reason. + /// context use, fitted to `budget` cells. The first candidate that fits + /// wins, in this order: + /// + /// 1. the full run status (phase and retry reason) with every optional part; + /// 2. the phase with the slot and the optional parts, dropping context, + /// then goal, then background tasks; + /// 3. the optional parts with the slot and without the phase, dropped the + /// same way; + /// 4. the slot alone. + /// + /// The slot outranks every other part, so it is never dropped for one. + /// When the slot alone is wider than the border, it is returned and the + /// caller clips it from its end. fn dock_status(&self, run: Option<(&str, &str)>, budget: usize) -> Option { let p = &self.palette; let slot = self.slot().map(|slot| { @@ -12395,6 +12404,71 @@ mod tests { assert!(!bottom.contains("goal"), "{bottom}"); assert!(!bottom.contains("dima-probe"), "{bottom}"); app.notice = None; + + // While running a retry, the same long notice still leads the corner. + app.apply(Update::Snapshot(Box::new(ViewSnapshot { + session_id: "s1".into(), + running: true, + retry: Some(crate::model::view::RetryView { + attempt: 2, + max_attempts: 8, + retry_at_ms: retry_at(60_000), + kind: dim_agent_types::ModelFailureKind::ServerError, + reason: Some("The provider reported a server error".into()), + }), + tasks: vec![background_task("t1", "cargo build")], + goal: Some(dim_agent_types::GoalView { + objective: "ship".into(), + status: dim_agent_types::GoalViewStatus::Active, + evaluator: false, + }), + ..ViewSnapshot::default() + }))); + app.set_notice("Interrupt requested; Ctrl+C again to exit"); + let (_, bottom, _) = composer_chrome(&mut app, 40); + assert!( + bottom.starts_with(" ╰─ Interrupt requested; Ctrl+C aga"), + "fullscreen {fullscreen}: the notice leads the running corner: {bottom}" + ); + assert!( + !bottom.contains("Retrying"), + "fullscreen {fullscreen}: {bottom}" + ); + app.notice = None; + + // Without a notice and without a background task, the phase goes + // before the goal: at 40 columns the phase with the slot does not + // fit, so the slot keeps the goal. + app.apply(Update::Snapshot(Box::new(ViewSnapshot { + session_id: "s1".into(), + running: true, + retry: Some(crate::model::view::RetryView { + attempt: 2, + max_attempts: 8, + retry_at_ms: retry_at(60_000), + kind: dim_agent_types::ModelFailureKind::ServerError, + reason: Some("The provider reported a server error".into()), + }), + goal: Some(dim_agent_types::GoalView { + objective: "ship".into(), + status: dim_agent_types::GoalViewStatus::Active, + evaluator: false, + }), + ..ViewSnapshot::default() + }))); + let (_, bottom, _) = composer_chrome(&mut app, 40); + assert!( + bottom.contains("esc interrupt"), + "fullscreen {fullscreen}: {bottom}" + ); + assert!( + bottom.contains("◎ goal active"), + "fullscreen {fullscreen}: {bottom}" + ); + assert!( + !bottom.contains("Retrying"), + "fullscreen {fullscreen}: {bottom}" + ); } } diff --git a/docs/design/cli-commands.md b/docs/design/cli-commands.md index e0f3f02dc8..f612a84bed 100644 --- a/docs/design/cli-commands.md +++ b/docs/design/cli-commands.md @@ -3105,11 +3105,13 @@ Both modes place the model label (with its effort when both fit) on the right si composer's top border, and keep the run status, the status slot (a notice, a required answer or permission, `esc interrupt`, or disconnect), background task count, goal and context information on the left side of the composer's bottom border, leaving only the permission -preset and its shortcut hint on the footer line. When the corner is too narrow, its parts -go in this order: first the context usage, then the goal, then the background task count. -The retry reason and the run status head go before the optional parts. The slot outranks -every other part: it is kept whole when it fits the border, and clipped from its end only -when the slot alone is wider than the border. While a prompt replaces the composer +preset and its shortcut hint on the footer line. When the corner is too narrow, the first +candidate that fits wins, in this order: (1) the full run status, with its retry reason, and +every optional part; (2) the phase with the slot and the optional parts, dropping context, +then goal, then background tasks; (3) the optional parts with the slot and without the phase, +dropped the same way; (4) the slot alone. The retry reason goes before the phase, and the +slot outranks every optional part, so it is kept whole when it fits the border. The slot +alone is clipped from its end only when it is wider than the border. While a prompt replaces the composer (permission, question, effort, exit, upgrade, fork, timeline, queue, export or report), the composer is not drawn, so a notice or the disconnect state is drawn once, on the rows just above the footer, and the footer stays permission-only. diff --git a/docs/zh/design/cli-commands.md b/docs/zh/design/cli-commands.md index 4f525bca35..2ec94b9117 100644 --- a/docs/zh/design/cli-commands.md +++ b/docs/zh/design/cli-commands.md @@ -1863,7 +1863,7 @@ Assistant: ... 按键行为见 [`/permissions`](#permissions)。页脚不提交到正文历史。 两种模式都把模型标签(放得下时连同推理强度)放在输入框上边框右侧,把运行状态、状态槽(通知、需要回答 或审批、`esc interrupt` 或断连)、后台任务数、目标与上下文信息放在输入框下边框左侧;页脚行只保留 -权限预设及其快捷键提示。下边框太窄时,各部分按此顺序让出:先去掉上下文用量,再去掉目标,最后去掉后台任务数;重试原因与运行状态的主体先于这些可选部分让出。状态槽优先于其他所有部分:只要能放进边框就保持完整,只有状态槽本身比边框还宽时才从末尾截断。输入框被弹窗替换时,通知或断连状态在页脚上方的若干行绘制一次,页脚仍只保留权限。 +权限预设及其快捷键提示。下边框太窄时,取第一个能放下的候选,顺序如下:(1)完整的运行状态(含重试原因)加上全部可选部分;(2)运行状态的主体(不含原因)与状态槽,加上可选部分,依次去掉上下文用量、目标、后台任务数;(3)可选部分与状态槽,不含运行状态的主体,去掉的顺序相同;(4)只剩状态槽。重试原因先于主体让出;状态槽优先于所有可选部分,只要能放进边框就保持完整,只有状态槽本身比边框还宽时才从末尾截断。输入框被弹窗替换时,通知或断连状态在页脚上方的若干行绘制一次,页脚仍只保留权限。 ### 提交检查的警告