mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
Show read-only conversations when resume encounters an active writer (#43253)
## Why Resuming a conversation that is open in another app fails with an active-writer error. Allow users to inspect its transcript and retry after closing it in the other app. ## What changed - Fall back to a read-only history snapshot on active-writer conflicts during startup and session selection. - Replace the composer with an explanatory notice, `R` to retry, exit shortcuts, and the configured transcript shortcut. - Block input and freeze active command and MCP animations while viewing the snapshot. Preserve initial prompts and existing drafts for a successful retry. - Keep the subscription when retrying the same thread and preserve read-only state across thread switches and reconnects. ## Testing Add regression tests for conflict detection, history viewing, draft preservation, same-thread retry without unsubscribing, exit shortcuts, and notice and frozen-tool rendering. GitOrigin-RevId: fa864cc73143cad9139c22e33b7958569eec20cf
This commit is contained in:
@@ -3,9 +3,121 @@
|
||||
use super::transcript::ActiveCellLayoutCache;
|
||||
use super::transcript::ActiveCellLayoutCacheKey;
|
||||
use super::*;
|
||||
use crate::render::RectExt;
|
||||
use crate::terminal_hyperlinks::HyperlinkParagraph;
|
||||
use crate::wrapping::RtOptions;
|
||||
use crate::wrapping::word_wrap_lines;
|
||||
use ratatui::style::Styled as _;
|
||||
use ratatui::text::Span;
|
||||
use ratatui::widgets::Block;
|
||||
use std::cell::Cell;
|
||||
|
||||
struct ExternalWriterNotice {
|
||||
transcript_hint: Option<crate::key_hint::ShortcutHint>,
|
||||
}
|
||||
|
||||
impl Renderable for ExternalWriterNotice {
|
||||
fn render(&self, area: Rect, buf: &mut Buffer) {
|
||||
let content_width = area.width.saturating_sub(/*rhs*/ 4);
|
||||
let card_lines = self.card_lines(content_width);
|
||||
let card_height = (card_lines.len() as u16).saturating_add(/*rhs*/ 2);
|
||||
let card = Rect::new(area.x, area.y, area.width, card_height.min(area.height));
|
||||
Widget::render(
|
||||
Block::default().style(crate::style::user_message_style()),
|
||||
card,
|
||||
buf,
|
||||
);
|
||||
let content = card.inset(Insets::tlbr(
|
||||
/*top*/ 1, /*left*/ 2, /*bottom*/ 1, /*right*/ 2,
|
||||
));
|
||||
Renderable::render(&Paragraph::new(card_lines), content, buf);
|
||||
let footer_y = card.bottom();
|
||||
if footer_y < area.bottom() {
|
||||
let footer = Rect::new(
|
||||
area.x.saturating_add(/*rhs*/ 2),
|
||||
footer_y,
|
||||
area.width.saturating_sub(/*rhs*/ 2),
|
||||
area.bottom().saturating_sub(footer_y),
|
||||
);
|
||||
Renderable::render(
|
||||
&Paragraph::new(self.footer_lines(footer.width)),
|
||||
footer,
|
||||
buf,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn desired_height(&self, width: u16) -> u16 {
|
||||
(self.card_lines(width.saturating_sub(/*rhs*/ 4)).len() as u16)
|
||||
.saturating_add(/*rhs*/ 2)
|
||||
.saturating_add(self.footer_lines(width.saturating_sub(/*rhs*/ 2)).len() as u16)
|
||||
}
|
||||
}
|
||||
|
||||
impl ExternalWriterNotice {
|
||||
fn card_lines(&self, width: u16) -> Vec<Line<'static>> {
|
||||
let title: Line<'static> = vec![
|
||||
"🔒".into(),
|
||||
" ".into(),
|
||||
"This conversation is open in another app".bold(),
|
||||
]
|
||||
.into();
|
||||
let retry: Line<'static> = vec![
|
||||
Span::styled("R", crate::style::accent_style()),
|
||||
" to Retry".into(),
|
||||
]
|
||||
.into();
|
||||
let mut lines = word_wrap_lines(&[title], usize::from(width));
|
||||
if lines.len() == 1 && lines[0].width() + retry.width() + 2 <= usize::from(width) {
|
||||
let gap = usize::from(width) - lines[0].width() - retry.width();
|
||||
lines[0].spans.push(" ".repeat(gap).into());
|
||||
lines[0].spans.extend(retry.spans);
|
||||
} else {
|
||||
lines.push(retry);
|
||||
}
|
||||
lines.extend(word_wrap_lines(
|
||||
&[Line::from(
|
||||
"Close it there and press R to continue here.".dim(),
|
||||
)],
|
||||
RtOptions::new(usize::from(width))
|
||||
.initial_indent(" ".into())
|
||||
.subsequent_indent(" ".into()),
|
||||
));
|
||||
lines
|
||||
}
|
||||
|
||||
fn footer_lines(&self, width: u16) -> Vec<Line<'static>> {
|
||||
let mut items = vec![
|
||||
("r".to_string(), "retry".to_string()),
|
||||
(
|
||||
format!(
|
||||
"{}/{}/{}",
|
||||
crate::key_hint::plain(KeyCode::Esc).display_label(),
|
||||
crate::key_hint::ctrl(KeyCode::Char('c')).display_label(),
|
||||
crate::key_hint::plain(KeyCode::Char('q')).display_label(),
|
||||
)
|
||||
.replace(" + ", "+"),
|
||||
"exit".to_string(),
|
||||
),
|
||||
];
|
||||
if let Some(hint) = self.transcript_hint {
|
||||
items.push((
|
||||
hint.display_label().replace(" + ", "+"),
|
||||
"transcript".to_string(),
|
||||
));
|
||||
}
|
||||
let mut spans = vec![" ".set_style(crate::style::footer_hint_label_style())];
|
||||
for (idx, (key, label)) in items.into_iter().enumerate() {
|
||||
if idx > 0 {
|
||||
spans.push(" ".set_style(crate::style::footer_hint_label_style()));
|
||||
}
|
||||
spans.push(key.set_style(crate::style::footer_hint_key_style()));
|
||||
spans.push(format!(" {label}").set_style(crate::style::footer_hint_label_style()));
|
||||
}
|
||||
word_wrap_lines(&[Line::from(spans)], usize::from(width))
|
||||
}
|
||||
}
|
||||
|
||||
impl ChatWidget {
|
||||
pub(crate) fn as_renderable(&self) -> RenderableItem<'_> {
|
||||
if self
|
||||
@@ -68,13 +180,19 @@ impl ChatWidget {
|
||||
})),
|
||||
);
|
||||
}
|
||||
flex.push(
|
||||
/*flex*/ 0,
|
||||
let bottom = if self.external_writer_view && !self.bottom_pane.has_active_view() {
|
||||
RenderableItem::Owned(Box::new(ExternalWriterNotice {
|
||||
transcript_hint: self.bottom_pane.transcript_shortcut_hint(),
|
||||
}))
|
||||
} else {
|
||||
self.bottom_pane
|
||||
.as_renderable_with_composer_right_reserve(active_cell_right_reserve)
|
||||
.inset(Insets::tlbr(
|
||||
/*top*/ 1, /*left*/ 0, /*bottom*/ 0, /*right*/ 0,
|
||||
)),
|
||||
};
|
||||
flex.push(
|
||||
/*flex*/ 0,
|
||||
bottom.inset(Insets::tlbr(
|
||||
/*top*/ 1, /*left*/ 0, /*bottom*/ 0, /*right*/ 0,
|
||||
)),
|
||||
);
|
||||
RenderableItem::Owned(Box::new(flex))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user