Repository navigation
Resume conversation from an earlier point in history - #2607
Conversation
There was a problem hiding this comment.
Codex Review: Here are some suggestions.
Reply with @codex fix comments to fix any unresolved comments.
About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you open a pull request for review, mark a draft as ready, or comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex fix this CI failure" or "@codex address that feedback".
Lower confidence thoughts:
|
nornagon-openai
left a comment
There was a problem hiding this comment.
overall this seems underbaked and in need of some careful attention to abstractions.
| fn rebuild_highlighted_lines(&mut self) { | ||
| // Start from base and optionally apply highlight styles to the target range. | ||
| let mut out = self.base_transcript_lines.clone(); | ||
| if let Some((start, end)) = self.highlight_range { | ||
| use ratatui::style::Modifier; | ||
| let len = out.len(); | ||
| let start = start.min(len); | ||
| let end = end.min(len); | ||
| for (idx, line) in out.iter_mut().enumerate().take(end).skip(start) { | ||
| // Apply REVERSED to all spans; add BOLD on the first line (header) | ||
| let mut spans = Vec::with_capacity(line.spans.len()); | ||
| for (i, s) in line.spans.iter().enumerate() { | ||
| let mut style = s.style; | ||
| style.add_modifier |= Modifier::REVERSED; | ||
| if idx == start && i == 0 { | ||
| style.add_modifier |= Modifier::BOLD; | ||
| } | ||
| spans.push(ratatui::text::Span { | ||
| style, | ||
| content: s.content.clone(), | ||
| }); | ||
| } | ||
| line.spans = spans; | ||
| } | ||
| } | ||
| self.transcript_lines = out; |
There was a problem hiding this comment.
can we instead apply highlighting at render time? then we can also drop base_transcript_lines.
| } | ||
| } | ||
| // Forward to overlay if not handled | ||
| if !handled && let Some(overlay) = &mut self.transcript_overlay { | ||
| overlay.handle_event(tui, event)?; | ||
| if overlay.is_done { | ||
| self.close_transcript_overlay(tui); | ||
| } | ||
| } |
There was a problem hiding this comment.
instead of mut handled, put the forwarding logic in the catchall case of the match
| pub(crate) fn render_transcript_once(&mut self, tui: &mut tui::Tui) { | ||
| if !self.transcript_lines.is_empty() { | ||
| tui.insert_history_lines(self.transcript_lines.clone()); | ||
| } |
There was a problem hiding this comment.
it seems bad to duplicate the history this way
There was a problem hiding this comment.
what other way you think is better?
There was a problem hiding this comment.
one possibility would be to render a separator (e.g. a line across the terminal), then "continuing from:" and then repeat only the most recent turn.
| pub(crate) fn handle_backtrack_esc_key(&mut self, tui: &mut tui::Tui) { | ||
| // Only handle backtracking when composer is empty to avoid clobbering edits. | ||
| if self.chat_widget.composer_is_empty() { | ||
| if !self.esc_backtrack_primed { | ||
| // Arm backtracking and record base conversation. | ||
| self.esc_backtrack_primed = true; | ||
| self.esc_backtrack_count = 0; | ||
| self.esc_backtrack_base = self.chat_widget.session_id(); | ||
| // Show hint in composer to guide Esc-then-Esc flow. | ||
| self.chat_widget.show_esc_backtrack_hint(); | ||
| } else if self.transcript_overlay.is_none() { | ||
| // Open transcript overlay in backtrack preview mode and jump to the target message. | ||
| self.open_transcript_overlay(tui); | ||
| self.transcript_overlay_is_backtrack = true; | ||
| // Overlay footer already shows the backtrack guidance unconditionally. | ||
| // Composer is hidden by overlay; clear its hint. | ||
| self.chat_widget.clear_esc_backtrack_hint(); | ||
| self.esc_backtrack_count = self.esc_backtrack_count.saturating_add(1); | ||
| let nth = backtrack_helpers::normalize_backtrack_n( | ||
| &self.transcript_lines, | ||
| self.esc_backtrack_count, | ||
| ); | ||
| self.esc_backtrack_count = nth; | ||
| let header_idx = | ||
| backtrack_helpers::find_nth_last_user_header_index(&self.transcript_lines, nth); | ||
| let offset = header_idx.map(|idx| { | ||
| backtrack_helpers::wrapped_offset_before( | ||
| &self.transcript_lines, | ||
| idx, | ||
| tui.terminal.viewport_area.width, | ||
| ) | ||
| }); | ||
| let hl = backtrack_helpers::highlight_range_for_nth_last_user( | ||
| &self.transcript_lines, | ||
| nth, | ||
| ); | ||
| if let Some(overlay) = &mut self.transcript_overlay { | ||
| if let Some(off) = offset { | ||
| overlay.scroll_offset = off; | ||
| } | ||
| overlay.set_highlight_range(hl); | ||
| } | ||
| } else if self.transcript_overlay_is_backtrack { | ||
| // Already previewing: step to the next older message. | ||
| self.esc_backtrack_count = self.esc_backtrack_count.saturating_add(1); | ||
| let nth = backtrack_helpers::normalize_backtrack_n( | ||
| &self.transcript_lines, | ||
| self.esc_backtrack_count, | ||
| ); | ||
| self.esc_backtrack_count = nth; | ||
| let header_idx = | ||
| backtrack_helpers::find_nth_last_user_header_index(&self.transcript_lines, nth); | ||
| let offset = header_idx.map(|idx| { | ||
| backtrack_helpers::wrapped_offset_before( | ||
| &self.transcript_lines, | ||
| idx, | ||
| tui.terminal.viewport_area.width, | ||
| ) | ||
| }); | ||
| let hl = backtrack_helpers::highlight_range_for_nth_last_user( | ||
| &self.transcript_lines, | ||
| nth, | ||
| ); | ||
| if let Some(overlay) = &mut self.transcript_overlay { | ||
| if let Some(off) = offset { | ||
| overlay.scroll_offset = off; | ||
| } | ||
| overlay.set_highlight_range(hl); | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
this seems like really brittle logic. i don't feel this is landable as is, it needs an abstraction in order to be understandable and thus modifiable.
Fixing merge conflict of this: #2588
Screen.Recording.2025-08-22.at.10.34.59.AM.mov