A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
fix iterm2 fullscreen blackout (#3468)
kta3390695e0b9
diff --git a/crates/pa-cli/tests/cursor_visibility_e2e.rs b/crates/pa-cli/tests/cursor_visibility_e2e.rsindex 13201ff1e0..765d849bb5 100644--- a/crates/pa-cli/tests/cursor_visibility_e2e.rs+++ b/crates/pa-cli/tests/cursor_visibility_e2e.rs@@ -216,6 +216,51 @@ fn cursor_stays_hidden_and_positioned_across_mount_picker_and_suspend() {harness.finish();}+#[test]+fn shell_markers_are_reserved_for_the_exit_transcript() {+ let _lock = HARNESS_LOCK+ .lock()+ .unwrap_or_else(std::sync::PoisonError::into_inner);+ let mut harness = CursorHarness::start();+ harness.wait_from_start("\x1b[?2026l", "the attached transcript frame finished");+ let mark = harness.mark();+ harness.write(b"hi");+ harness.wait_from(+ mark,+ "\x1b[?25l\x1b[20;7H",+ "the editor parked the hidden caret after the typed text",+ );+ let mark = harness.mark();+ harness.write(b"\x7f\x7f");+ harness.wait_from(+ mark,+ "\x1b[?25l\x1b[20;5H",+ "the editor emptied back to the bare caret",+ );+ harness.write(b"\x04");+ harness.wait_from_start("\x1b[?1049l", "exit restored the main screen");+ harness.wait_from_start("\x1b]133;C\x07", "exit replayed the marked transcript");+ harness.wait_from_start("test result: ok", "the interactive child exited cleanly");+ let output = harness.output();+ harness.finish();++ let leave = find_subsequence(&output, b"\x1b[?1049l").expect("alternate screen exit");+ let (fullscreen, transcript) = output.split_at(leave);+ assert!(find_subsequence(fullscreen, b"row 0").is_some());+ assert!(+ find_subsequence(fullscreen, b"\x1b]133;").is_none(),+ "shell prompt markers must not change the terminal's grid during fullscreen painting"+ );+ for marker in [b"\x1b]133;A\x07", b"\x1b]133;B\x07", b"\x1b]133;C\x07"] {+ assert!(+ find_subsequence(transcript, marker).is_some(),+ "exit retains shell integration"+ );+ }+ assert!(find_subsequence(transcript, b"row 0").is_some());+ assert!(find_subsequence(transcript, b"row 3").is_some());+}+/// One pty-backed product child plus the mock supervisor it attaches to.struct CursorHarness {child: Child,diff --git a/crates/pa-tui/src/app.rs b/crates/pa-tui/src/app.rsindex 79ebf7833e..6a38494a6a 100644--- a/crates/pa-tui/src/app.rs+++ b/crates/pa-tui/src/app.rs@@ -270,9 +270,9 @@ pub(crate) fn draw(// The frame's embedded OSC 8 sequences drive the paint backend's hyperlink injection; install// the ranges before the draw (which strips the sequences from the painted cells).crate::hyperlinks::install_frame(&frame);- // Zone markers ride on the composed rows; plan their emission before the cell paint- // (which strips them), then write the sequences at their rows after the frame is painted.- let emissions = view.take_osc_emissions(&frame);+ // OSC 133 describes shell prompts, not alternate-screen rows. In iTerm2 it can+ // disable soft alternate-screen mode and let cursor moves clear the painted grid.+ // Keep those markers in the main-screen exit transcript only.// Fullscreen paint brackets the row diff in synchronized output so terminals never display// an intermediate, partly scrolled frame; a terminal without mode 2026 support ignores the// two escape sequences.@@ -304,15 +304,9 @@ pub(crate) fn draw(}}}- let markers = if painted.is_ok() {- emit_zone_markers(&emissions, cursor)- } else {- Ok(())- };// Always release the terminal's pending update, including on paint errors.crossterm::execute!(stdout(), terminal::EndSynchronizedUpdate)?;painted?;- markers?;if mounting {// Mode setup flushes stdout, so it must follow the completed first paint.crate::enhanced_keys::enable(&mut stdout())?;@@ -320,35 +314,6 @@ pub(crate) fn draw(Ok(())}-/// Write OSC 133 zone-marker sequences at their frame rows. The sequences are zero-width: only-/// the row flags the shell integration reads change; the frame cursor is restored afterwards.-fn emit_zone_markers(- emissions: &[(usize, crate::osc133::RowMarkers)],- cursor: Option<(usize, usize)>,-) -> Result<()> {- use crossterm::cursor::MoveTo;- use std::io::Write;- if emissions.is_empty() {- return Ok(());- }- let mut out = stdout();- for (row, markers) in emissions {- crossterm::queue!(out, MoveTo(0, *row as u16))?;- if markers.start {- out.write_all(crate::osc133::ZONE_START.as_bytes())?;- }- if markers.end {- out.write_all(crate::osc133::ZONE_END.as_bytes())?;- out.write_all(crate::osc133::ZONE_FINAL.as_bytes())?;- }- }- if let Some((row, col)) = cursor {- crossterm::queue!(out, MoveTo(col as u16, row as u16))?;- }- out.flush()?;- Ok(())-}-/// Render one frame as plain text (the headless structural dump the tmux verifier and diff/// tests use). ANSI styling and OSC zone markers are stripped.pub fn render_frame_text(view: &mut AgentView, width: u16, height: u16) -> Vec<String> {diff --git a/crates/pa-tui/src/osc133.rs b/crates/pa-tui/src/osc133.rsindex 453b020c8d..724d41734e 100644--- a/crates/pa-tui/src/osc133.rs+++ b/crates/pa-tui/src/osc133.rs@@ -2,7 +2,7 @@//! standard prompt/output zone sequences so shell-integration users get working jumps between turns//! — `A` starts a marked row, `B` then `C` land at the start of the component's last row. The//! sequences are zero-width: `width` skips them, the ratatui paint path strips them from cell-//! content, and `app::draw` re-emits them per row after the frame is painted.+//! content. Only the main-screen transcript flush emits them to the terminal.use crate::Line;@@ -27,15 +27,17 @@ pub fn mark_end(line: &mut Line) {}/// Which zone sequences a rendered row carries.+#[cfg(test)]#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]-pub struct RowMarkers {+pub(crate) struct RowMarkers {pub start: bool,pub end: bool,}/// Detect the zone sequences at the start of a rendered row.+#[cfg(test)]#[must_use]-pub fn row_markers(line: &Line) -> RowMarkers {+pub(crate) fn row_markers(line: &Line) -> RowMarkers {let joined: String = line.iter().map(|s| s.content.as_str()).collect();let mut markers = RowMarkers::default();if joined.starts_with(ZONE_START) {@@ -81,20 +83,6 @@ fn markers_only(content: &str) -> bool {!content.is_empty() && rest.is_empty()}-/// Per-frame row marker plan: `(terminal row, markers)` for every marked row, in row order.-#[must_use]-pub fn frame_markers(frame: &[Line]) -> Vec<(usize, RowMarkers)> {- frame- .iter()- .enumerate()- .filter(|(_, line)| {- let m = row_markers(line);- m.start || m.end- })- .map(|(row, line)| (row, row_markers(line)))- .collect()-}-#[cfg(test)]mod tests {use super::*;@@ -144,33 +132,4 @@ mod tests {strip(&mut only_marker);assert!(only_marker.is_empty());}-- #[test]- fn frame_markers_report_marked_rows() {- let mut frame = vec![row(), row(), row()];- mark_start(&mut frame[0]);- mark_end(&mut frame[2]);- let plan = frame_markers(&frame);- assert_eq!(plan.len(), 2);- assert_eq!(- plan[0],- (- 0,- RowMarkers {- start: true,- end: false- }- )- );- assert_eq!(- plan[1],- (- 2,- RowMarkers {- start: false,- end: true- }- )- );- }}diff --git a/crates/pa-tui/src/view.rs b/crates/pa-tui/src/view.rsindex c43ab5e5c7..ee3303a15c 100644--- a/crates/pa-tui/src/view.rs+++ b/crates/pa-tui/src/view.rs@@ -135,9 +135,6 @@ pub struct AgentView {/// The hovered screen cell, while its row is a clickable card row/// (operator directive 2026-09-26); revalidated every frame.pub(crate) hover_pos: Option<(usize, usize)>,- /// Plain text of the last frame's rows: OSC zone-marker emission only- /// re-emits rows whose content changed.- osc_last_rows: std::collections::HashMap<usize, String>,/// Rendered rows per chat entry and detail mode: a frame re-renders only entries invalidated/// since the last frame, so a transcript-scale frame pays full layout once per entry/detail.entry_layout: Vec<[Option<EntryLayout>; 3]>,@@ -326,7 +323,6 @@ impl AgentView {window_shows_tail: false,detail_transition: false,hover_pos: None,- osc_last_rows: std::collections::HashMap::new(),toasts: crate::toast::Toasts::default(),entry_layout: Vec::new(),entry_heights: Vec::new(),@@ -349,35 +345,6 @@ impl AgentView {}}- /// Zone-marker emission plan for a freshly composed frame: every- /// marked row whose content changed since the last frame.- pub fn take_osc_emissions(- &mut self,- frame: &[Line],- ) -> Vec<(usize, crate::osc133::RowMarkers)> {- // Only candidate rows build their text: joining the whole frame- // costs O(transcript) per render.- let mut plan = Vec::new();- let mut last_rows = std::collections::HashMap::new();- for (row, line) in frame.iter().enumerate() {- let markers = crate::osc133::row_markers(line);- if !markers.start && !markers.end {- continue;- }- let text: String = line.iter().map(|s| s.content.as_str()).collect();- let changed = self- .osc_last_rows- .get(&row)- .is_none_or(|prev| prev != &text);- if changed {- plan.push((row, markers));- }- last_rows.insert(row, text);- }- self.osc_last_rows = last_rows;- plan- }-pub fn terminal_rows(&self) -> u16 {self.terminal_rows}diff --git a/crates/pa-tui/src/view/tests.rs b/crates/pa-tui/src/view/tests.rsindex b5433007ef..c19a6054b5 100644--- a/crates/pa-tui/src/view/tests.rs+++ b/crates/pa-tui/src/view/tests.rs@@ -251,23 +251,6 @@ fn frame_is_exactly_height_rows() {assert!(joined.contains('>'));}-#[test]-fn osc_emissions_reemit_only_changed_rows() {- let mut v = view();- v.chrome.version = "0.0.0".to_string();- v.chrome.cwd = "/w".to_string();- v.chrome.chat_name = "w".to_string();- v.push(TranscriptItem::UserMessage {- text: "hello".to_string(),- });- let frame = v.render_frame(80, 24);- let first = v.take_osc_emissions(&frame);- let marked: Vec<usize> = first.iter().map(|(row, _)| *row).collect();- assert!(!marked.is_empty());- let again = v.take_osc_emissions(&frame);- assert!(again.is_empty());-}-/// Fill the transcript past one window so there is scrollable history.fn filled(mut v: AgentView, turns: usize) -> AgentView {v.chrome.version = "0.0.0".to_string();