diff --git a/CONTEXT.md b/CONTEXT.md index 458cbf5224..e4d2e074b2 100644 --- a/CONTEXT.md +++ b/CONTEXT.md @@ -74,6 +74,12 @@ _Avoid_: TUI API, local story service **reviewStory**: The app-server v2 API namespace for **Story API** methods. It is separate from the findings-oriented `review` namespace because its artifact explains rather than judges a change. +**Story Overlay**: +The TUI presentation of a completed **Story Snapshot**. It provides an ordered steps rail, step details, changed evidence, and compact-layout contents view without mutating or regenerating the story. + +**/story**: +The TUI command that starts story creation for a selected **Concrete Story Source** and opens its resulting **Story Overlay**. The review picker also exposes the same story action. + ## Deferred Concepts These terms describe intended follow-up work, not behavior delivered by the current API/backend implementation. @@ -87,9 +93,6 @@ A possible future evidence model that adds hunk anchors, commit relationships, o **Progressive Story Snapshot** and **Step Enrichment**: A future asynchronous generation workflow in which an ordered outline is usable before every step has complete explanatory prose. Current generation uses one blocking model grouping call and stores one completed snapshot. -**Story Overlay** and **/story**: -A future TUI surface and entry point over the shared API. They are intentionally implemented in a stacked UI change rather than in the reusable backend base layer. - ## Example Dialogue Dev: "Does Review Story find bugs?" diff --git a/codex-rs/tui/src/app/event_dispatch.rs b/codex-rs/tui/src/app/event_dispatch.rs index e150dbccd2..972b92dacc 100644 --- a/codex-rs/tui/src/app/event_dispatch.rs +++ b/codex-rs/tui/src/app/event_dispatch.rs @@ -1835,12 +1835,28 @@ impl App { AppEvent::OpenReviewBranchPicker(cwd) => { self.chat_widget.show_review_branch_picker(&cwd).await; } + AppEvent::OpenReviewStoryPopup => { + self.chat_widget.open_review_story_popup(); + } + AppEvent::OpenReviewStoryBranchPicker(cwd) => { + self.chat_widget.show_review_story_branch_picker(&cwd).await; + } AppEvent::OpenReviewCommitPicker(cwd) => { self.chat_widget.show_review_commit_picker(&cwd).await; } + AppEvent::OpenReviewStoryCommitPicker(cwd) => { + self.chat_widget.show_review_story_commit_picker(&cwd).await; + } AppEvent::OpenReviewCustomPrompt => { self.chat_widget.show_review_custom_prompt(); } + AppEvent::ReviewStoryReady(snapshot) => { + let _ = tui.enter_alt_screen(); + self.overlay = Some(Overlay::new_review_story( + snapshot, + self.keymap.pager.clone(), + )); + } AppEvent::SubmitUserMessageWithMode { text, collaboration_mode, diff --git a/codex-rs/tui/src/app/thread_routing.rs b/codex-rs/tui/src/app/thread_routing.rs index 8f15aed79a..d57c26b97e 100644 --- a/codex-rs/tui/src/app/thread_routing.rs +++ b/codex-rs/tui/src/app/thread_routing.rs @@ -654,6 +654,14 @@ impl App { app_server.review_start(thread_id, target.clone()).await?; Ok(true) } + AppCommand::ReviewStory { target } => { + let response = app_server + .review_story_start(thread_id, target.clone()) + .await?; + self.app_event_tx + .send(AppEvent::ReviewStoryReady(response.snapshot)); + Ok(true) + } AppCommand::CleanBackgroundTerminals => { app_server .thread_background_terminals_clean(thread_id) diff --git a/codex-rs/tui/src/app_command.rs b/codex-rs/tui/src/app_command.rs index 2ecf17f5a3..50c2d4fb35 100644 --- a/codex-rs/tui/src/app_command.rs +++ b/codex-rs/tui/src/app_command.rs @@ -105,6 +105,9 @@ pub(crate) enum AppCommand { Review { target: ReviewTarget, }, + ReviewStory { + target: ReviewTarget, + }, ApproveGuardianDeniedAction { event: GuardianAssessmentEvent, }, @@ -272,6 +275,10 @@ impl AppCommand { Self::Review { target } } + pub(crate) fn review_story(target: ReviewTarget) -> Self { + Self::ReviewStory { target } + } + pub(crate) fn approve_guardian_denied_action(event: GuardianAssessmentEvent) -> Self { Self::ApproveGuardianDeniedAction { event } } diff --git a/codex-rs/tui/src/app_event.rs b/codex-rs/tui/src/app_event.rs index 17b749971a..d115810aa6 100644 --- a/codex-rs/tui/src/app_event.rs +++ b/codex-rs/tui/src/app_event.rs @@ -24,6 +24,7 @@ use codex_app_server_protocol::PluginReadParams; use codex_app_server_protocol::PluginReadResponse; use codex_app_server_protocol::PluginUninstallResponse; use codex_app_server_protocol::RateLimitSnapshot; +use codex_app_server_protocol::ReviewStorySnapshot; use codex_app_server_protocol::SkillsListResponse; use codex_app_server_protocol::ThreadGoalStatus; use codex_file_search::FileMatch; @@ -885,13 +886,19 @@ pub(crate) enum AppEvent { /// Open the branch picker option from the review popup. OpenReviewBranchPicker(PathBuf), + OpenReviewStoryPopup, + OpenReviewStoryBranchPicker(PathBuf), /// Open the commit picker option from the review popup. OpenReviewCommitPicker(PathBuf), + OpenReviewStoryCommitPicker(PathBuf), /// Open the custom prompt option from the review popup. OpenReviewCustomPrompt, + /// Open the review story overlay for a freshly generated snapshot. + ReviewStoryReady(ReviewStorySnapshot), + /// Submit a user message with an explicit collaboration mask. SubmitUserMessageWithMode { text: String, diff --git a/codex-rs/tui/src/app_event_sender.rs b/codex-rs/tui/src/app_event_sender.rs index 5b8da9ec09..d26dd34454 100644 --- a/codex-rs/tui/src/app_event_sender.rs +++ b/codex-rs/tui/src/app_event_sender.rs @@ -59,6 +59,10 @@ impl AppEventSender { self.send(AppEvent::CodexOp(AppCommand::review(target))); } + pub(crate) fn review_story(&self, target: ReviewTarget) { + self.send(AppEvent::CodexOp(AppCommand::review_story(target))); + } + pub(crate) fn list_skills(&self, cwds: Vec, force_reload: bool) { self.send(AppEvent::CodexOp(AppCommand::list_skills( cwds, diff --git a/codex-rs/tui/src/app_server_session.rs b/codex-rs/tui/src/app_server_session.rs index 59d56ca56e..bb3f400ad8 100644 --- a/codex-rs/tui/src/app_server_session.rs +++ b/codex-rs/tui/src/app_server_session.rs @@ -40,6 +40,8 @@ use codex_app_server_protocol::RequestId; use codex_app_server_protocol::ReviewDelivery; use codex_app_server_protocol::ReviewStartParams; use codex_app_server_protocol::ReviewStartResponse; +use codex_app_server_protocol::ReviewStoryStartParams; +use codex_app_server_protocol::ReviewStoryStartResponse; use codex_app_server_protocol::ReviewTarget; use codex_app_server_protocol::SkillsListParams; use codex_app_server_protocol::SkillsListResponse; @@ -978,6 +980,24 @@ impl AppServerSession { .wrap_err("review/start failed in TUI") } + pub(crate) async fn review_story_start( + &mut self, + thread_id: ThreadId, + target: ReviewTarget, + ) -> Result { + let request_id = self.next_request_id(); + self.client + .request_typed(ClientRequest::ReviewStoryStart { + request_id, + params: ReviewStoryStartParams { + thread_id: thread_id.to_string(), + target, + }, + }) + .await + .wrap_err("reviewStory/start failed in TUI") + } + pub(crate) async fn skills_list( &mut self, params: SkillsListParams, diff --git a/codex-rs/tui/src/chatwidget/review_popups.rs b/codex-rs/tui/src/chatwidget/review_popups.rs index b069649ef3..b894bb483b 100644 --- a/codex-rs/tui/src/chatwidget/review_popups.rs +++ b/codex-rs/tui/src/chatwidget/review_popups.rs @@ -6,6 +6,17 @@ impl ChatWidget { pub(crate) fn open_review_popup(&mut self) { let mut items: Vec = Vec::new(); + items.push(SelectionItem { + name: "Create review story".to_string(), + description: Some("Step-by-step walkthrough".into()), + actions: vec![Box::new(move |tx| { + tx.send(AppEvent::OpenReviewStoryPopup); + })], + dismiss_on_select: false, + dismiss_parent_on_child_accept: true, + ..Default::default() + }); + items.push(SelectionItem { name: "Review against a base branch".to_string(), description: Some("(PR Style)".into()), @@ -60,6 +71,53 @@ impl ChatWidget { }); } + pub(crate) fn open_review_story_popup(&mut self) { + let mut items: Vec = Vec::new(); + + items.push(SelectionItem { + name: "Story against a base branch".to_string(), + description: Some("(PR Style)".into()), + actions: vec![Box::new({ + let cwd = self.config.cwd.to_path_buf(); + move |tx| { + tx.send(AppEvent::OpenReviewStoryBranchPicker(cwd.clone())); + } + })], + dismiss_on_select: false, + dismiss_parent_on_child_accept: true, + ..Default::default() + }); + + items.push(SelectionItem { + name: "Story for uncommitted changes".to_string(), + actions: vec![Box::new(move |tx: &AppEventSender| { + tx.review_story(ReviewTarget::UncommittedChanges); + })], + dismiss_on_select: true, + ..Default::default() + }); + + items.push(SelectionItem { + name: "Story for a commit".to_string(), + actions: vec![Box::new({ + let cwd = self.config.cwd.to_path_buf(); + move |tx| { + tx.send(AppEvent::OpenReviewStoryCommitPicker(cwd.clone())); + } + })], + dismiss_on_select: false, + dismiss_parent_on_child_accept: true, + ..Default::default() + }); + + self.bottom_pane.show_selection_view(SelectionViewParams { + title: Some("Select a review story source".into()), + footer_hint: Some(standard_popup_hint_line()), + items, + ..Default::default() + }); + } + pub(crate) async fn show_review_branch_picker(&mut self, cwd: &Path) { let branches = local_git_branches(cwd).await; let current_branch = current_branch_name(cwd) @@ -92,6 +150,38 @@ impl ChatWidget { }); } + pub(crate) async fn show_review_story_branch_picker(&mut self, cwd: &Path) { + let branches = local_git_branches(cwd).await; + let current_branch = current_branch_name(cwd) + .await + .unwrap_or_else(|| "(detached HEAD)".to_string()); + let mut items: Vec = Vec::with_capacity(branches.len()); + + for option in branches { + let branch = option.clone(); + items.push(SelectionItem { + name: format!("{current_branch} -> {branch}"), + actions: vec![Box::new(move |tx3: &AppEventSender| { + tx3.review_story(ReviewTarget::BaseBranch { + branch: branch.clone(), + }); + })], + dismiss_on_select: true, + search_value: Some(option), + ..Default::default() + }); + } + + self.bottom_pane.show_selection_view(SelectionViewParams { + title: Some("Select a base branch".to_string()), + footer_hint: Some(standard_popup_hint_line()), + items, + is_searchable: true, + search_placeholder: Some("Type to search branches".to_string()), + ..Default::default() + }); + } + pub(crate) async fn show_review_commit_picker(&mut self, cwd: &Path) { let commits = recent_commits(cwd, /*limit*/ 100).await; @@ -125,6 +215,39 @@ impl ChatWidget { }); } + pub(crate) async fn show_review_story_commit_picker(&mut self, cwd: &Path) { + let commits = recent_commits(cwd, /*limit*/ 100).await; + + let mut items: Vec = Vec::with_capacity(commits.len()); + for entry in commits { + let subject = entry.subject.clone(); + let sha = entry.sha.clone(); + let search_val = format!("{subject} {sha}"); + + items.push(SelectionItem { + name: subject.clone(), + actions: vec![Box::new(move |tx3: &AppEventSender| { + tx3.review_story(ReviewTarget::Commit { + sha: sha.clone(), + title: Some(subject.clone()), + }); + })], + dismiss_on_select: true, + search_value: Some(search_val), + ..Default::default() + }); + } + + self.bottom_pane.show_selection_view(SelectionViewParams { + title: Some("Select a commit for the story".to_string()), + footer_hint: Some(standard_popup_hint_line()), + items, + is_searchable: true, + search_placeholder: Some("Type to search commits".to_string()), + ..Default::default() + }); + } + pub(crate) fn show_review_custom_prompt(&mut self) { let tx = self.app_event_tx.clone(); let view = CustomPromptView::new( diff --git a/codex-rs/tui/src/chatwidget/slash_dispatch.rs b/codex-rs/tui/src/chatwidget/slash_dispatch.rs index b479718304..c6161827b7 100644 --- a/codex-rs/tui/src/chatwidget/slash_dispatch.rs +++ b/codex-rs/tui/src/chatwidget/slash_dispatch.rs @@ -195,6 +195,9 @@ impl ChatWidget { SlashCommand::Review => { self.open_review_popup(); } + SlashCommand::Story => { + self.open_review_story_popup(); + } SlashCommand::Rename => { self.session_telemetry .counter("codex.thread.rename", /*inc*/ 1, &[]); @@ -955,6 +958,7 @@ impl ChatWidget { | SlashCommand::Init | SlashCommand::Compact | SlashCommand::Review + | SlashCommand::Story | SlashCommand::Model | SlashCommand::Realtime | SlashCommand::Settings diff --git a/codex-rs/tui/src/chatwidget/tests/review_mode.rs b/codex-rs/tui/src/chatwidget/tests/review_mode.rs index 48bc341f6b..0117349026 100644 --- a/codex-rs/tui/src/chatwidget/tests/review_mode.rs +++ b/codex-rs/tui/src/chatwidget/tests/review_mode.rs @@ -1038,7 +1038,8 @@ async fn review_popup_custom_prompt_action_sends_event() { // Open the preset selection popup chat.open_review_popup(); - // Move selection down to the fourth item: "Custom review instructions" + // Move selection down to the fifth item: "Custom review instructions" + chat.handle_key_event(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE)); chat.handle_key_event(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE)); chat.handle_key_event(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE)); chat.handle_key_event(KeyEvent::new(KeyCode::Down, KeyModifiers::NONE)); diff --git a/codex-rs/tui/src/diff_render.rs b/codex-rs/tui/src/diff_render.rs index 350c3c7aa0..188bc191ee 100644 --- a/codex-rs/tui/src/diff_render.rs +++ b/codex-rs/tui/src/diff_render.rs @@ -352,6 +352,34 @@ pub(crate) fn create_diff_summary( render_changes_block(rows, wrap_cols, cwd) } +/// Render a raw git file patch using the standard TUI diff presentation. +/// +/// Review story anchors preserve git's file headers, while `diffy` expects the +/// unified portion beginning at `---`; callers can fall back to raw lines if +/// this returns no styled rows for a non-empty patch. +pub(crate) fn render_story_anchor_diff( + patch: &str, + path: &Path, + width: usize, +) -> Vec> { + let unified = patch + .lines() + .skip_while(|line| !line.starts_with("--- ")) + .collect::>() + .join("\n"); + if unified.is_empty() { + return Vec::new(); + } + let change = FileChange::Update { + unified_diff: format!("{unified}\n"), + move_path: None, + }; + let mut lines = Vec::new(); + let lang = detect_lang_for_path(path); + render_change(&change, &mut lines, width, lang.as_deref()); + lines +} + // Shared row for per-file presentation #[derive(Clone)] struct Row { diff --git a/codex-rs/tui/src/lib.rs b/codex-rs/tui/src/lib.rs index 7348e3b452..e0fae534bd 100644 --- a/codex-rs/tui/src/lib.rs +++ b/codex-rs/tui/src/lib.rs @@ -163,6 +163,7 @@ pub(crate) mod public_widgets; mod render; mod resize_reflow_cap; mod resume_picker; +mod review_story_overlay; mod selection_list; mod service_tier_resolution; mod session_log; diff --git a/codex-rs/tui/src/pager_overlay.rs b/codex-rs/tui/src/pager_overlay.rs index c301700eaa..00d12e977f 100644 --- a/codex-rs/tui/src/pager_overlay.rs +++ b/codex-rs/tui/src/pager_overlay.rs @@ -28,6 +28,7 @@ use crate::keymap::PagerKeymap; use crate::render::Insets; use crate::render::renderable::InsetRenderable; use crate::render::renderable::Renderable; +use crate::review_story_overlay::ReviewStoryOverlay; use crate::style::user_message_style; use crate::tui; use crate::tui::TuiEvent; @@ -50,6 +51,7 @@ use ratatui::widgets::Wrap; pub(crate) enum Overlay { Transcript(TranscriptOverlay), Static(StaticOverlay), + ReviewStory(ReviewStoryOverlay), } impl Overlay { @@ -73,10 +75,18 @@ impl Overlay { Self::Static(StaticOverlay::with_renderables(renderables, title, keymap)) } + pub(crate) fn new_review_story( + snapshot: codex_app_server_protocol::ReviewStorySnapshot, + keymap: PagerKeymap, + ) -> Self { + Self::ReviewStory(ReviewStoryOverlay::new(snapshot, keymap)) + } + pub(crate) fn handle_event(&mut self, tui: &mut tui::Tui, event: TuiEvent) -> Result<()> { match self { Overlay::Transcript(o) => o.handle_event(tui, event), Overlay::Static(o) => o.handle_event(tui, event), + Overlay::ReviewStory(o) => o.handle_event(tui, event), } } @@ -84,6 +94,7 @@ impl Overlay { match self { Overlay::Transcript(o) => o.is_done(), Overlay::Static(o) => o.is_done(), + Overlay::ReviewStory(o) => o.is_done(), } } } diff --git a/codex-rs/tui/src/review_story_overlay.rs b/codex-rs/tui/src/review_story_overlay.rs new file mode 100644 index 0000000000..3ab2996357 --- /dev/null +++ b/codex-rs/tui/src/review_story_overlay.rs @@ -0,0 +1,625 @@ +//! Interactive full-screen presentation for completed review story snapshots. + +use std::collections::HashSet; +use std::io::Result; + +use codex_app_server_protocol::ReviewStorySnapshot; +use codex_app_server_protocol::ReviewStorySnapshotStatus; +use crossterm::event::KeyCode; +use crossterm::event::KeyEvent; +use crossterm::event::KeyEventKind; +use crossterm::event::KeyModifiers; +use ratatui::buffer::Buffer; +use ratatui::layout::Constraint; +use ratatui::layout::Direction; +use ratatui::layout::Layout; +use ratatui::layout::Rect; +use ratatui::style::Style; +use ratatui::style::Stylize; +use ratatui::text::Line; +use ratatui::widgets::Block; +use ratatui::widgets::Borders; +use ratatui::widgets::Clear; +use ratatui::widgets::Paragraph; +use ratatui::widgets::Widget; + +use crate::key_hint::KeyBindingListExt; +use crate::keymap::PagerKeymap; +use crate::tui; +use crate::tui::TuiEvent; + +mod render_helpers; + +use self::render_helpers::adjust_scroll; +use self::render_helpers::centered_rect; +use self::render_helpers::clamped_scroll; +use self::render_helpers::diff_lines; +use self::render_helpers::help_lines; +use self::render_helpers::pane_block; +use self::render_helpers::primary_label; +use self::render_helpers::source_label; +use self::render_helpers::step_state_label; + +const NARROW_WIDTH: u16 = 72; +const NARROW_HEIGHT: u16 = 18; + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +enum Pane { + Steps, + Details, + Diff, +} + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +enum Subview { + Overview, + Help, + Contents, +} + +pub(crate) struct ReviewStoryOverlay { + snapshot: ReviewStorySnapshot, + selected_step: usize, + visited_steps: HashSet, + focused_pane: Pane, + details_scroll: u16, + diff_scroll: u16, + active_anchor: usize, + subview: Option, + keymap: PagerKeymap, + layout_is_narrow: bool, + is_done: bool, +} + +impl ReviewStoryOverlay { + pub(crate) fn new(snapshot: ReviewStorySnapshot, keymap: PagerKeymap) -> Self { + let visited_steps = snapshot + .steps + .first() + .map(|step| HashSet::from([step.step_id.clone()])) + .unwrap_or_default(); + Self { + snapshot, + selected_step: 0, + visited_steps, + focused_pane: Pane::Steps, + details_scroll: 0, + diff_scroll: 0, + active_anchor: 0, + subview: None, + keymap, + layout_is_narrow: false, + is_done: false, + } + } + + pub(crate) fn handle_event(&mut self, tui: &mut tui::Tui, event: TuiEvent) -> Result<()> { + match event { + TuiEvent::Key(key) => { + self.handle_key_event(key); + tui.frame_requester().schedule_frame(); + Ok(()) + } + TuiEvent::Draw | TuiEvent::Resize => tui.draw(u16::MAX, |frame| { + self.render(frame.area(), frame.buffer); + }), + _ => Ok(()), + } + } + + pub(crate) fn is_done(&self) -> bool { + self.is_done + } + + fn handle_key_event(&mut self, key: KeyEvent) { + if !matches!(key.kind, KeyEventKind::Press | KeyEventKind::Repeat) { + return; + } + if self.handle_subview_key(key) { + return; + } + if self.keymap.close.is_pressed(key) || key.code == KeyCode::Esc { + self.is_done = true; + return; + } + match key.code { + KeyCode::Char('n') if key.modifiers == KeyModifiers::NONE => { + self.move_step(/*amount*/ 1); + } + KeyCode::Char('p') if key.modifiers == KeyModifiers::NONE => { + self.move_step(/*amount*/ -1); + } + KeyCode::Tab if key.modifiers == KeyModifiers::NONE => self.next_pane(), + KeyCode::BackTab => self.previous_pane(), + KeyCode::Enter if self.focused_pane == Pane::Steps => self.focused_pane = Pane::Diff, + KeyCode::Char('[') if self.focused_pane == Pane::Diff => { + self.move_anchor(/*amount*/ -1); + } + KeyCode::Char(']') if self.focused_pane == Pane::Diff => { + self.move_anchor(/*amount*/ 1); + } + KeyCode::Char('o') if key.modifiers == KeyModifiers::NONE => { + self.subview = Some(Subview::Overview); + } + KeyCode::Char('?') if key.modifiers == KeyModifiers::NONE => { + self.subview = Some(Subview::Help); + } + KeyCode::Char('t') if key.modifiers == KeyModifiers::NONE => { + self.subview = Some(Subview::Contents); + } + _ => self.handle_pane_navigation(key), + } + } + + fn handle_subview_key(&mut self, key: KeyEvent) -> bool { + let Some(subview) = self.subview else { + return false; + }; + if key.code == KeyCode::Esc + || matches!(key.code, KeyCode::Char('o')) && subview == Subview::Overview + || matches!(key.code, KeyCode::Char('?')) && subview == Subview::Help + || matches!(key.code, KeyCode::Char('t')) && subview == Subview::Contents + { + self.subview = None; + return true; + } + if subview == Subview::Contents { + if self.keymap.scroll_up.is_pressed(key) { + self.move_step(/*amount*/ -1); + } else if self.keymap.scroll_down.is_pressed(key) { + self.move_step(/*amount*/ 1); + } else if key.code == KeyCode::Enter { + self.subview = None; + self.focused_pane = Pane::Details; + } + } + true + } + + fn handle_pane_navigation(&mut self, key: KeyEvent) { + if self.keymap.scroll_up.is_pressed(key) { + self.scroll_or_select(/*amount*/ -1); + } else if self.keymap.scroll_down.is_pressed(key) { + self.scroll_or_select(/*amount*/ 1); + } else if self.keymap.page_up.is_pressed(key) || self.keymap.half_page_up.is_pressed(key) { + self.scroll_or_select(/*amount*/ -8); + } else if self.keymap.page_down.is_pressed(key) + || self.keymap.half_page_down.is_pressed(key) + { + self.scroll_or_select(/*amount*/ 8); + } else if self.keymap.jump_top.is_pressed(key) { + self.jump(/*bottom*/ false); + } else if self.keymap.jump_bottom.is_pressed(key) { + self.jump(/*bottom*/ true); + } + } + + fn scroll_or_select(&mut self, amount: i32) { + match self.focused_pane { + Pane::Steps => self.move_step(amount), + Pane::Details => adjust_scroll(&mut self.details_scroll, amount), + Pane::Diff => adjust_scroll(&mut self.diff_scroll, amount), + } + } + + fn jump(&mut self, bottom: bool) { + match self.focused_pane { + Pane::Steps => { + let selected = if bottom { + self.snapshot.steps.len().saturating_sub(1) + } else { + 0 + }; + self.select_step(selected); + } + Pane::Details => self.details_scroll = if bottom { u16::MAX } else { 0 }, + Pane::Diff => self.diff_scroll = if bottom { u16::MAX } else { 0 }, + } + } + + fn move_step(&mut self, amount: i32) { + if self.snapshot.steps.is_empty() { + return; + } + let selected = (self.selected_step as i32 + amount) + .clamp(0, self.snapshot.steps.len().saturating_sub(1) as i32) + as usize; + self.select_step(selected); + } + + fn select_step(&mut self, selected: usize) { + if selected == self.selected_step || selected >= self.snapshot.steps.len() { + return; + } + self.selected_step = selected; + self.details_scroll = 0; + self.diff_scroll = 0; + self.active_anchor = 0; + self.visited_steps + .insert(self.snapshot.steps[selected].step_id.clone()); + } + + fn move_anchor(&mut self, amount: i32) { + let anchors = self.selected_anchors(); + if anchors.is_empty() { + return; + } + self.active_anchor = (self.active_anchor as i32 + amount) + .clamp(0, anchors.len().saturating_sub(1) as i32) as usize; + self.diff_scroll = 0; + } + + fn next_pane(&mut self) { + if self.layout_is_narrow { + self.focused_pane = match self.focused_pane { + Pane::Details => Pane::Diff, + Pane::Diff | Pane::Steps => Pane::Details, + }; + return; + } + self.focused_pane = match self.focused_pane { + Pane::Steps => Pane::Details, + Pane::Details => Pane::Diff, + Pane::Diff => Pane::Steps, + }; + } + + fn previous_pane(&mut self) { + if self.layout_is_narrow { + self.focused_pane = match self.focused_pane { + Pane::Details => Pane::Diff, + Pane::Diff | Pane::Steps => Pane::Details, + }; + return; + } + self.focused_pane = match self.focused_pane { + Pane::Steps => Pane::Diff, + Pane::Details => Pane::Steps, + Pane::Diff => Pane::Details, + }; + } + + fn is_narrow(area: Rect) -> bool { + area.width < NARROW_WIDTH || area.height < NARROW_HEIGHT + } + + pub(crate) fn render(&mut self, area: Rect, buf: &mut Buffer) { + self.layout_is_narrow = Self::is_narrow(area); + if self.layout_is_narrow && self.focused_pane == Pane::Steps { + self.focused_pane = Pane::Details; + } + Clear.render(area, buf); + let shell = Block::default() + .borders(Borders::ALL) + .title(" REVIEW STORY "); + let inner = shell.inner(area); + shell.render(area, buf); + let vertical = Layout::default() + .direction(Direction::Vertical) + .constraints([ + Constraint::Length(2), + Constraint::Min(4), + Constraint::Length(1), + ]) + .split(inner); + self.render_header(vertical[0], buf); + if self.layout_is_narrow { + self.render_narrow_body(vertical[1], buf); + } else { + self.render_full_body(vertical[1], buf); + } + self.render_footer(vertical[2], buf, self.layout_is_narrow); + if let Some(subview) = self.subview { + self.render_subview(area, buf, subview); + } + } + + fn render_header(&self, area: Rect, buf: &mut Buffer) { + let status = match self.snapshot.status { + ReviewStorySnapshotStatus::Ready => "ready".green(), + ReviewStorySnapshotStatus::Partial => "partial".magenta(), + ReviewStorySnapshotStatus::Building => "building".cyan(), + ReviewStorySnapshotStatus::Failed => "failed".red(), + }; + let position = format!( + "{}/{}", + self.snapshot + .steps + .get(self.selected_step) + .map_or(0, |_| self.selected_step + 1), + self.snapshot.steps.len() + ); + let mut metadata = vec![ + source_label(&self.snapshot.target).dim(), + " ".into(), + format!("{} files", self.snapshot.anchors.len()).dim(), + " ".into(), + status, + " ".into(), + position.bold(), + ]; + if self.snapshot.stale { + metadata.extend([" ".into(), "stale".magenta()]); + } + Paragraph::new(vec![ + self.snapshot.title.clone().bold().into(), + metadata.into(), + ]) + .render(area, buf); + } + + fn render_full_body(&mut self, area: Rect, buf: &mut Buffer) { + let columns = Layout::default() + .direction(Direction::Horizontal) + .constraints([ + Constraint::Length((area.width / 4).clamp(18, 32)), + Constraint::Min(30), + ]) + .split(area); + self.render_steps(columns[0], buf); + let rows = Layout::default() + .direction(Direction::Vertical) + .constraints([Constraint::Percentage(43), Constraint::Percentage(57)]) + .split(columns[1]); + self.render_details(rows[0], buf); + self.render_diff(rows[1], buf); + } + + fn render_narrow_body(&mut self, area: Rect, buf: &mut Buffer) { + let rows = Layout::default() + .direction(Direction::Vertical) + .constraints([Constraint::Percentage(42), Constraint::Percentage(58)]) + .split(area); + self.render_details(rows[0], buf); + self.render_diff(rows[1], buf); + } + + fn render_steps(&self, area: Rect, buf: &mut Buffer) { + let block = pane_block(" STEPS ", self.focused_pane == Pane::Steps); + let inner = block.inner(area); + block.render(area, buf); + let lines = self + .snapshot + .steps + .iter() + .enumerate() + .map(|(index, step)| { + let marker = if index == self.selected_step { + ">".cyan().bold() + } else if self.visited_steps.contains(&step.step_id) { + "x".green() + } else { + ".".dim() + }; + let state = step_state_label(step); + vec![ + marker, + format!(" {} ", step.index).dim(), + step.title.clone().into(), + state, + ] + .into() + }) + .collect::>>(); + Paragraph::new(lines).render(inner, buf); + } + + fn render_details(&self, area: Rect, buf: &mut Buffer) { + let title = self + .selected_step() + .map(|step| format!(" DETAILS - {} ", step.title)) + .unwrap_or_else(|| " DETAILS ".to_string()); + let block = pane_block(&title, self.focused_pane == Pane::Details); + let inner = block.inner(area); + block.render(area, buf); + let lines = self.details_lines(inner.width.max(1)); + let offset = clamped_scroll(self.details_scroll, lines.len(), inner.height); + Paragraph::new(lines).scroll((offset, 0)).render(inner, buf); + } + + fn render_diff(&mut self, area: Rect, buf: &mut Buffer) { + let anchors = self.selected_anchors(); + let count = anchors.len(); + let position = if count == 0 { + 0 + } else { + self.active_anchor.min(count - 1) + 1 + }; + let title = format!(" DIFF - file {position}/{count} "); + let block = pane_block(&title, self.focused_pane == Pane::Diff); + let inner = block.inner(area); + block.render(area, buf); + let (lines, offsets) = diff_lines(&anchors, inner.width.max(1)); + if self.active_anchor < offsets.len() && self.diff_scroll == 0 && self.active_anchor > 0 { + self.diff_scroll = offsets[self.active_anchor] as u16; + } + let offset = clamped_scroll(self.diff_scroll, lines.len(), inner.height); + Paragraph::new(lines).scroll((offset, 0)).render(inner, buf); + } + + fn render_footer(&self, area: Rect, buf: &mut Buffer, narrow: bool) { + let focus = match self.focused_pane { + Pane::Steps => "STEPS", + Pane::Details => "DETAILS", + Pane::Diff => "DIFF", + }; + let close = primary_label(&self.keymap.close, "esc"); + let scroll = format!( + "{}/{}", + primary_label(&self.keymap.scroll_up, "up"), + primary_label(&self.keymap.scroll_down, "down") + ); + let text = if narrow { + format!(" {focus} n/p step {scroll} scroll tab pane t contents {close} close") + } else { + format!( + " {focus} n/p step {scroll} scroll tab pane [/] file o overview ? help {close} close" + ) + }; + Paragraph::new(text.dim()).render(area, buf); + } + + fn render_subview(&self, area: Rect, buf: &mut Buffer, subview: Subview) { + let popup = centered_rect(area, /*width_percent*/ 72, /*height_percent*/ 70); + Clear.render(popup, buf); + let title = match subview { + Subview::Overview => " OVERVIEW ", + Subview::Help => " HELP ", + Subview::Contents => " CONTENTS ", + }; + let block = Block::default() + .borders(Borders::ALL) + .title(title) + .border_style(Style::default().cyan()); + let inner = block.inner(popup); + block.render(popup, buf); + let lines = match subview { + Subview::Overview => self.overview_lines(inner.width.max(1)), + Subview::Help => help_lines(), + Subview::Contents => self.contents_lines(), + }; + Paragraph::new(lines).render(inner, buf); + } +} + +#[cfg(test)] +mod tests { + use super::*; + use codex_app_server_protocol::ReviewStoryAnchor; + use codex_app_server_protocol::ReviewStoryAnchorKind; + use codex_app_server_protocol::ReviewStoryStep; + use codex_app_server_protocol::ReviewStoryStepReadiness; + use codex_app_server_protocol::ReviewTarget; + use insta::assert_snapshot; + use pretty_assertions::assert_eq; + use ratatui::Terminal; + use ratatui::backend::TestBackend; + + fn default_keymap() -> PagerKeymap { + crate::keymap::RuntimeKeymap::defaults().pager + } + + fn snapshot() -> ReviewStorySnapshot { + ReviewStorySnapshot { + story_snapshot_id: "story-1".to_string(), + thread_id: "thread-1".to_string(), + title: "Introduce review story navigation".to_string(), + overview: "A stored narrative orders the API and terminal changes for review." + .to_string(), + target: ReviewTarget::BaseBranch { + branch: "main".to_string(), + }, + source_fingerprint: "source-1234".to_string(), + status: ReviewStorySnapshotStatus::Ready, + created_at: 1, + updated_at: 2, + previous_story_snapshot_id: None, + stale: false, + steps: vec![ + ReviewStoryStep { + step_id: "api".to_string(), + index: 1, + title: "Define the artifact".to_string(), + goal: "Expose a reusable snapshot contract.".to_string(), + summary: "Adds the v2 request and response types.".to_string(), + dependency_rationale: "The interface precedes any presentation layer." + .to_string(), + anchor_ids: vec!["protocol".to_string()], + review_focus: vec!["Confirm the wire format can support both clients." + .to_string()], + readiness: ReviewStoryStepReadiness::Ready, + error: None, + }, + ReviewStoryStep { + step_id: "tui".to_string(), + index: 2, + title: "Navigate the story".to_string(), + goal: "Let a reviewer move step by step.".to_string(), + summary: "Adds a focused cockpit with diff evidence.".to_string(), + dependency_rationale: "The surface consumes the completed contract." + .to_string(), + anchor_ids: vec!["overlay".to_string()], + review_focus: vec!["Check compact terminal behavior.".to_string()], + readiness: ReviewStoryStepReadiness::Ready, + error: None, + }, + ], + anchors: vec![ + ReviewStoryAnchor { + anchor_id: "protocol".to_string(), + file_path: "app-server-protocol/src/review_story.rs".to_string(), + change_kind: ReviewStoryAnchorKind::Added, + summary: "Adds shared story payloads.".to_string(), + diff: "diff --git a/protocol.rs b/protocol.rs\n--- a/protocol.rs\n+++ b/protocol.rs\n@@ -1 +1,2 @@\n pub struct Thread;\n+pub struct Story;\n".to_string(), + }, + ReviewStoryAnchor { + anchor_id: "overlay".to_string(), + file_path: "tui/src/review_story_overlay.rs".to_string(), + change_kind: ReviewStoryAnchorKind::Added, + summary: "Adds the story cockpit.".to_string(), + diff: "diff --git a/overlay.rs b/overlay.rs\n--- /dev/null\n+++ b/overlay.rs\n@@ -0,0 +1 @@\n+struct ReviewStoryOverlay;\n".to_string(), + }, + ], + } + } + + fn render(overlay: &mut ReviewStoryOverlay, width: u16, height: u16) -> TestBackend { + let mut terminal = Terminal::new(TestBackend::new(width, height)).expect("terminal"); + terminal + .draw(|frame| overlay.render(frame.area(), frame.buffer_mut())) + .expect("draw"); + terminal.backend().clone() + } + + #[test] + fn full_cockpit_snapshot() { + let mut overlay = ReviewStoryOverlay::new(snapshot(), default_keymap()); + + assert_snapshot!(render(&mut overlay, /*width*/ 116, /*height*/ 30)); + } + + #[test] + fn compact_cockpit_snapshot_hides_steps_rail() { + let mut overlay = ReviewStoryOverlay::new(snapshot(), default_keymap()); + + assert_snapshot!(render(&mut overlay, /*width*/ 68, /*height*/ 22)); + assert_eq!(overlay.focused_pane, Pane::Details); + } + + #[test] + fn overview_subview_snapshot() { + let mut overlay = ReviewStoryOverlay::new(snapshot(), default_keymap()); + overlay.subview = Some(Subview::Overview); + + assert_snapshot!(render(&mut overlay, /*width*/ 116, /*height*/ 30)); + } + + #[test] + fn navigation_resets_step_scroll_and_tracks_visited_steps() { + let mut overlay = ReviewStoryOverlay::new(snapshot(), default_keymap()); + overlay.details_scroll = 4; + overlay.diff_scroll = 3; + overlay.active_anchor = 1; + + overlay.handle_key_event(KeyEvent::new(KeyCode::Char('n'), KeyModifiers::NONE)); + + assert_eq!(overlay.selected_step, 1); + assert_eq!(overlay.details_scroll, 0); + assert_eq!(overlay.diff_scroll, 0); + assert_eq!(overlay.active_anchor, 0); + assert!(overlay.visited_steps.contains("tui")); + } + + #[test] + fn escape_closes_a_subview_before_closing_the_story() { + let mut overlay = ReviewStoryOverlay::new(snapshot(), default_keymap()); + overlay.subview = Some(Subview::Help); + + overlay.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE)); + assert_eq!(overlay.subview, None); + assert!(!overlay.is_done); + + overlay.handle_key_event(KeyEvent::new(KeyCode::Esc, KeyModifiers::NONE)); + assert!(overlay.is_done); + } +} diff --git a/codex-rs/tui/src/review_story_overlay/render_helpers.rs b/codex-rs/tui/src/review_story_overlay/render_helpers.rs new file mode 100644 index 0000000000..3d912ec916 --- /dev/null +++ b/codex-rs/tui/src/review_story_overlay/render_helpers.rs @@ -0,0 +1,267 @@ +use std::path::Path; + +use codex_app_server_protocol::ReviewStoryAnchor; +use codex_app_server_protocol::ReviewStoryStep; +use codex_app_server_protocol::ReviewStoryStepReadiness; +use codex_app_server_protocol::ReviewTarget; +use ratatui::layout::Constraint; +use ratatui::layout::Direction; +use ratatui::layout::Layout; +use ratatui::layout::Rect; +use ratatui::style::Style; +use ratatui::style::Stylize; +use ratatui::text::Line; +use ratatui::widgets::Block; +use ratatui::widgets::Borders; + +use super::ReviewStoryOverlay; +use crate::diff_render::render_story_anchor_diff; +use crate::key_hint::KeyBinding; + +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +enum TextKind { + Normal, + Error, +} + +impl ReviewStoryOverlay { + pub(super) fn selected_step(&self) -> Option<&ReviewStoryStep> { + self.snapshot.steps.get(self.selected_step) + } + + pub(super) fn selected_anchors(&self) -> Vec { + let Some(step) = self.selected_step() else { + return Vec::new(); + }; + step.anchor_ids + .iter() + .filter_map(|id| { + self.snapshot + .anchors + .iter() + .find(|anchor| &anchor.anchor_id == id) + }) + .cloned() + .collect() + } + + pub(super) fn details_lines(&self, width: u16) -> Vec> { + let Some(step) = self.selected_step() else { + return vec!["No story steps.".dim().into()]; + }; + let mut lines = Vec::new(); + if let Some(error) = &step.error { + push_text(&mut lines, "ERROR", error, width, TextKind::Error); + } + push_text(&mut lines, "GOAL", &step.goal, width, TextKind::Normal); + push_text(&mut lines, "WHAT", &step.summary, width, TextKind::Normal); + push_text( + &mut lines, + "WHY HERE", + &step.dependency_rationale, + width, + TextKind::Normal, + ); + if !step.review_focus.is_empty() { + lines.push("FOCUS".bold().into()); + for focus in &step.review_focus { + for wrapped in textwrap::wrap(focus, width.saturating_sub(2).max(1) as usize) { + lines.push(vec!["- ".dim(), wrapped.into_owned().into()].into()); + } + } + } + lines + } + + pub(super) fn overview_lines(&self, width: u16) -> Vec> { + let mut lines = vec![self.snapshot.title.clone().bold().into(), Line::from("")]; + push_text( + &mut lines, + "OVERVIEW", + &self.snapshot.overview, + width, + TextKind::Normal, + ); + lines.push(Line::from("")); + lines.push(format!("Source: {}", source_label(&self.snapshot.target)).into()); + lines.push( + format!( + "Files: {} Steps: {}", + self.snapshot.anchors.len(), + self.snapshot.steps.len() + ) + .into(), + ); + lines.push( + format!("Fingerprint: {}", self.snapshot.source_fingerprint) + .dim() + .into(), + ); + lines + } + + pub(super) fn contents_lines(&self) -> Vec> { + self.snapshot + .steps + .iter() + .enumerate() + .map(|(index, step)| { + let marker = if index == self.selected_step { + ">".cyan().bold() + } else { + " ".into() + }; + vec![ + marker, + format!(" {}. ", step.index).dim(), + step.title.clone().into(), + ] + .into() + }) + .collect() + } +} + +pub(super) fn adjust_scroll(scroll: &mut u16, amount: i32) { + if amount.is_negative() { + *scroll = scroll.saturating_sub(amount.unsigned_abs() as u16); + } else { + *scroll = scroll.saturating_add(amount as u16); + } +} + +pub(super) fn clamped_scroll(scroll: u16, line_count: usize, height: u16) -> u16 { + scroll.min(line_count.saturating_sub(height as usize) as u16) +} + +pub(super) fn pane_block(title: &str, focused: bool) -> Block<'_> { + let style = if focused { + Style::default().cyan() + } else { + Style::default().dim() + }; + Block::default() + .borders(Borders::ALL) + .title(title.to_string()) + .border_style(style) +} + +pub(super) fn source_label(target: &ReviewTarget) -> String { + match target { + ReviewTarget::BaseBranch { branch } => format!("base: {branch}...HEAD"), + ReviewTarget::UncommittedChanges => "uncommitted changes".to_string(), + ReviewTarget::Commit { sha, .. } => { + format!("commit {}", sha.chars().take(8).collect::()) + } + ReviewTarget::Custom { .. } => "custom source".to_string(), + } +} + +pub(super) fn step_state_label(step: &ReviewStoryStep) -> ratatui::text::Span<'static> { + if step.error.is_some() || step.readiness == ReviewStoryStepReadiness::Failed { + " !".red() + } else { + match step.readiness { + ReviewStoryStepReadiness::Outline => " o".dim(), + ReviewStoryStepReadiness::Enriching => " ~".cyan(), + ReviewStoryStepReadiness::Ready => "".into(), + ReviewStoryStepReadiness::Failed => " !".red(), + } + } +} + +fn push_text(lines: &mut Vec>, label: &str, text: &str, width: u16, kind: TextKind) { + if text.trim().is_empty() { + return; + } + let label = label.to_string(); + lines.push(if kind == TextKind::Error { + label.red().bold().into() + } else { + label.bold().into() + }); + lines.extend( + textwrap::wrap(text, width.max(1) as usize) + .into_iter() + .map(|line| Line::from(line.into_owned())), + ); + lines.push(Line::from("")); +} + +pub(super) fn diff_lines( + anchors: &[ReviewStoryAnchor], + width: u16, +) -> (Vec>, Vec) { + if anchors.is_empty() { + return (vec!["(no diff)".dim().into()], Vec::new()); + } + let mut lines = Vec::new(); + let mut offsets = Vec::new(); + for anchor in anchors { + offsets.push(lines.len()); + lines.push( + vec![ + anchor.file_path.clone().bold(), + " ".into(), + format!("{:?}", anchor.change_kind).to_lowercase().dim(), + ] + .into(), + ); + if !anchor.summary.is_empty() { + lines.push(anchor.summary.clone().dim().into()); + } + let rendered = + render_story_anchor_diff(&anchor.diff, Path::new(&anchor.file_path), width as usize); + if rendered.is_empty() { + lines.extend( + anchor + .diff + .lines() + .map(|line| line.to_string().dim().into()), + ); + } else { + lines.extend(rendered); + } + lines.push(Line::from("")); + } + (lines, offsets) +} + +pub(super) fn help_lines() -> Vec> { + vec![ + "n / p next / previous step".into(), + "tab change focused pane".into(), + "up / down select or scroll focused pane".into(), + "[ / ] previous / next file in Diff".into(), + "o story overview".into(), + "t contents (narrow layout)".into(), + "q / esc close".into(), + ] +} + +pub(super) fn primary_label(bindings: &[KeyBinding], fallback: &str) -> String { + bindings + .first() + .map(KeyBinding::display_label) + .unwrap_or_else(|| fallback.to_string()) +} + +pub(super) fn centered_rect(area: Rect, width_percent: u16, height_percent: u16) -> Rect { + let vertical = Layout::default() + .direction(Direction::Vertical) + .constraints([ + Constraint::Percentage((100 - height_percent) / 2), + Constraint::Percentage(height_percent), + Constraint::Percentage((100 - height_percent) / 2), + ]) + .split(area); + let horizontal = Layout::default() + .direction(Direction::Horizontal) + .constraints([ + Constraint::Percentage((100 - width_percent) / 2), + Constraint::Percentage(width_percent), + Constraint::Percentage((100 - width_percent) / 2), + ]) + .split(vertical[1]); + horizontal[1] +} diff --git a/codex-rs/tui/src/slash_command.rs b/codex-rs/tui/src/slash_command.rs index 4a43409296..edd7c2d358 100644 --- a/codex-rs/tui/src/slash_command.rs +++ b/codex-rs/tui/src/slash_command.rs @@ -28,6 +28,7 @@ pub enum SlashCommand { Skills, Hooks, Review, + Story, Rename, New, Resume, @@ -84,6 +85,7 @@ impl SlashCommand { SlashCommand::Init => "create an AGENTS.md file with instructions for Codex", SlashCommand::Compact => "summarize conversation to prevent hitting the context limit", SlashCommand::Review => "review my current changes and find issues", + SlashCommand::Story => "explain changes as a step-by-step review story", SlashCommand::Rename => "rename the current thread", SlashCommand::Resume => "resume a saved chat", SlashCommand::Clear => "clear the terminal and start a new chat", @@ -148,6 +150,7 @@ impl SlashCommand { matches!( self, SlashCommand::Review + | SlashCommand::Story | SlashCommand::Rename | SlashCommand::Plan | SlashCommand::Goal @@ -194,6 +197,7 @@ impl SlashCommand { | SlashCommand::Experimental | SlashCommand::Memories | SlashCommand::Review + | SlashCommand::Story | SlashCommand::Plan | SlashCommand::Clear | SlashCommand::Logout diff --git a/codex-rs/tui/src/snapshots/codex_tui__review_story_overlay__tests__compact_cockpit_snapshot_hides_steps_rail.snap b/codex-rs/tui/src/snapshots/codex_tui__review_story_overlay__tests__compact_cockpit_snapshot_hides_steps_rail.snap new file mode 100644 index 0000000000..8ccbee56f3 --- /dev/null +++ b/codex-rs/tui/src/snapshots/codex_tui__review_story_overlay__tests__compact_cockpit_snapshot_hides_steps_rail.snap @@ -0,0 +1,26 @@ +--- +source: tui/src/review_story_overlay.rs +expression: "render(&mut overlay, 68, 22)" +--- +"┌ REVIEW STORY ────────────────────────────────────────────────────┐" +"│Introduce review story navigation │" +"│base: main...HEAD 2 files ready 1/2 │" +"│┌ DETAILS - Define the artifact ─────────────────────────────────┐│" +"││GOAL ││" +"││Expose a reusable snapshot contract. ││" +"││ ││" +"││WHAT ││" +"││Adds the v2 request and response types. ││" +"│└────────────────────────────────────────────────────────────────┘│" +"│┌ DIFF - file 1/1 ───────────────────────────────────────────────┐│" +"││app-server-protocol/src/review_story.rs added ││" +"││Adds shared story payloads. ││" +"││1 pub struct Thread; ││" +"││2 +pub struct Story; ││" +"││ ││" +"││ ││" +"││ ││" +"││ ││" +"│└────────────────────────────────────────────────────────────────┘│" +"│ DETAILS n/p step ↑/↓ scroll tab pane t contents q close │" +"└──────────────────────────────────────────────────────────────────┘" diff --git a/codex-rs/tui/src/snapshots/codex_tui__review_story_overlay__tests__full_cockpit_snapshot.snap b/codex-rs/tui/src/snapshots/codex_tui__review_story_overlay__tests__full_cockpit_snapshot.snap new file mode 100644 index 0000000000..294c34debe --- /dev/null +++ b/codex-rs/tui/src/snapshots/codex_tui__review_story_overlay__tests__full_cockpit_snapshot.snap @@ -0,0 +1,34 @@ +--- +source: tui/src/review_story_overlay.rs +expression: "render(&mut overlay, 116, 30)" +--- +"┌ REVIEW STORY ────────────────────────────────────────────────────────────────────────────────────────────────────┐" +"│Introduce review story navigation │" +"│base: main...HEAD 2 files ready 1/2 │" +"│┌ STEPS ───────────────────┐┌ DETAILS - Define the artifact ─────────────────────────────────────────────────────┐│" +"││> 1 Define the artifact ││GOAL ││" +"││. 2 Navigate the story ││Expose a reusable snapshot contract. ││" +"││ ││ ││" +"││ ││WHAT ││" +"││ ││Adds the v2 request and response types. ││" +"││ ││ ││" +"││ ││WHY HERE ││" +"││ ││The interface precedes any presentation layer. ││" +"││ ││ ││" +"││ │└────────────────────────────────────────────────────────────────────────────────────┘│" +"││ │┌ DIFF - file 1/1 ───────────────────────────────────────────────────────────────────┐│" +"││ ││app-server-protocol/src/review_story.rs added ││" +"││ ││Adds shared story payloads. ││" +"││ ││1 pub struct Thread; ││" +"││ ││2 +pub struct Story; ││" +"││ ││ ││" +"││ ││ ││" +"││ ││ ││" +"││ ││ ││" +"││ ││ ││" +"││ ││ ││" +"││ ││ ││" +"││ ││ ││" +"│└──────────────────────────┘└────────────────────────────────────────────────────────────────────────────────────┘│" +"│ STEPS n/p step ↑/↓ scroll tab pane [/] file o overview ? help q close │" +"└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘" diff --git a/codex-rs/tui/src/snapshots/codex_tui__review_story_overlay__tests__overview_subview_snapshot.snap b/codex-rs/tui/src/snapshots/codex_tui__review_story_overlay__tests__overview_subview_snapshot.snap new file mode 100644 index 0000000000..7431721324 --- /dev/null +++ b/codex-rs/tui/src/snapshots/codex_tui__review_story_overlay__tests__overview_subview_snapshot.snap @@ -0,0 +1,34 @@ +--- +source: tui/src/review_story_overlay.rs +expression: "render(&mut overlay, 116, 30)" +--- +"┌ REVIEW STORY ────────────────────────────────────────────────────────────────────────────────────────────────────┐" +"│Introduce review story navigation │" +"│base: main...HEAD 2 files ready 1/2 │" +"│┌ STEPS ───────────────────┐┌ DETAILS - Define the artifact ─────────────────────────────────────────────────────┐│" +"││> 1 Define the artifact ││GOAL ││" +"││. 2 Navigate t┌ OVERVIEW ────────────────────────────────────────────────────────────────────────┐ ││" +"││ │Introduce review story navigation │ ││" +"││ │ │ ││" +"││ │OVERVIEW │ ││" +"││ │A stored narrative orders the API and terminal changes for review. │ ││" +"││ │ │ ││" +"││ │ │ ││" +"││ │Source: base: main...HEAD │ ││" +"││ │Files: 2 Steps: 2 │──────────────┘│" +"││ │Fingerprint: source-1234 │──────────────┐│" +"││ │ │ ││" +"││ │ │ ││" +"││ │ │ ││" +"││ │ │ ││" +"││ │ │ ││" +"││ │ │ ││" +"││ │ │ ││" +"││ │ │ ││" +"││ │ │ ││" +"││ │ │ ││" +"││ └──────────────────────────────────────────────────────────────────────────────────┘ ││" +"││ ││ ││" +"│└──────────────────────────┘└────────────────────────────────────────────────────────────────────────────────────┘│" +"│ STEPS n/p step ↑/↓ scroll tab pane [/] file o overview ? help q close │" +"└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘" diff --git a/docs/adr/0001-review-story-v1.md b/docs/adr/0001-review-story-v1.md index 33f17c49df..34330d5781 100644 --- a/docs/adr/0001-review-story-v1.md +++ b/docs/adr/0001-review-story-v1.md @@ -18,9 +18,11 @@ The API also provides `reviewStory/read` and `reviewStory/list` for stored snaps Story snapshots live in the story store rather than in thread transcript history. The API is the product boundary: a stacked TUI feature and a later App UI can present the same stored story artifact. +The stacked TUI layer provides `/story` and a Review picker action. It renders completed snapshots in a read-only cockpit with ordered steps, selected-step rationale, associated file patches, overview/help/contents subviews, and a compact terminal layout. It does not perform progressive enrichment or update snapshots in place. + ## Deliberately Deferred -- Interactive TUI or App UI presentation. +- App UI presentation. - Progressive outline-first generation and asynchronous step enrichment. - Hunk-level anchors, dependency graph signals, or semantic indexing. - Staleness detection, refresh, and snapshot lineage behavior.