Skip to content

A self-improving RLM agent for coding workflows and long-running autonomous tasks.

Rust

wrap complete oauth login urls in narrow terminals (#3535)

kt4b690f979492
diff --git a/.changes/wrap-oauth-login-urls.md b/.changes/wrap-oauth-login-urls.md
new file mode 100644
index 0000000000..7aeb82b15c
--- /dev/null
+++ b/.changes/wrap-oauth-login-urls.md
@@ -0,0 +1 @@
+- Wrap complete sign-in URLs and login actions in narrow terminals, giving the onboarding login panel more space when needed.
diff --git a/crates/pa-tui/src/auth_panel/render.rs b/crates/pa-tui/src/auth_panel/render.rs
index a5aa73dabe..08c4658ff2 100644
--- a/crates/pa-tui/src/auth_panel/render.rs
+++ b/crates/pa-tui/src/auth_panel/render.rs
@@ -96,24 +96,37 @@ impl AuthPanel {
// execute terminal control operations; a URL is single-line. The link renders wrapped
// in OSC 8 (the URL is the display text) when the terminal implements hyperlinks.
let safe = scrub_controls(url).replace('\n', "");
- // The OSC 8 wrap survives truncation intact: the display text truncates BEFORE the
- // wrap (a long URL cut mid-sequence would leave the link region open); the URI
- // carries the full URL.
- let budget = width.saturating_sub(2);
- let display = if crate::width::str_width(&safe) > budget {
- crate::width::truncate_line(&vec![Span::raw(safe.clone())], budget, "")
- .iter()
- .map(|span| span.content.clone())
- .collect::<String>()
- } else {
- safe.clone()
- };
- let linked = if crate::hyperlinks::hyperlinks_enabled() {
- format!("{}{display}{OSC8_CLOSE}", osc8_open(&safe))
- } else {
- display
+ // Wrap the visible URL before adding OSC 8: every row must retain a complete
+ // target and a closing sequence. Wrapping the escape-bearing string can split it.
+ // The wrap is character-level, not word-level: a URL is one token, and word wrap
+ // drops the spaces `scrub_controls` emits for control characters at the breaks -
+ // the visible rows would no longer match the copied or linked target.
+ let budget = width.saturating_sub(2).max(1);
+ let push_url_row = |lines: &mut Vec<Line>, display: &str| {
+ let linked = if crate::hyperlinks::hyperlinks_enabled() {
+ format!("{}{display}{OSC8_CLOSE}", osc8_open(&safe))
+ } else {
+ display.to_string()
+ };
+ // At one column there is no room for the usual indent as well as the URL.
+ lines.push(vec![
+ Span::raw(if width > 1 { " " } else { "" }),
+ theme.fg_span(ThemeColor::Text, linked),
+ ]);
};
- lines.push(content_row(theme, width, ThemeColor::Text, &linked));
+ let mut display = String::new();
+ let mut display_width = 0usize;
+ for c in safe.chars() {
+ let char_width = crate::width::char_width(c);
+ if display_width + char_width > budget && !display.is_empty() {
+ push_url_row(&mut lines, &display);
+ display.clear();
+ display_width = 0;
+ }
+ display.push(c);
+ display_width += char_width;
+ }
+ push_url_row(&mut lines, &display);
// The browser-step text reads apart from the URL.
lines.push(Vec::new());
let instructions = self.auth_instructions.clone().map_or_else(
@@ -227,13 +240,14 @@ impl AuthPanel {
// The URL block's actions row rides last — the copy-key hint with the copy status,
// the submit hint while the paste field is mounted, and the cancel hint.
if self.auth_url.is_some() {
- lines.push(auth_actions_row(
+ let actions = auth_actions_row(
theme,
- width,
+ usize::MAX,
kb,
matches!(self.input, PanelInput::Paste { .. }),
self.copy_status,
- ));
+ );
+ lines.extend(crate::width::wrap_line(&actions, width));
}
lines
}
diff --git a/crates/pa-tui/src/auth_panel/tests.rs b/crates/pa-tui/src/auth_panel/tests.rs
index 7be6b05383..efa517e6df 100644
--- a/crates/pa-tui/src/auth_panel/tests.rs
+++ b/crates/pa-tui/src/auth_panel/tests.rs
@@ -686,3 +686,146 @@ fn the_copy_binding_copies_the_mounted_url_into_the_actions_row() {
"the plain key typed into the field: {rows:?}"
);
}
+
+/// Headless login exposes every URL byte even when the terminal cannot carry OSC 8 links.
+#[test]
+fn long_auth_url_wraps_without_losing_bytes_or_controls() {
+ let url = format!("https://auth.openai.com/oauth/authorize?response_type=code&client_id=fixture&redirect_uri=http%3A%2F%2Flocalhost%3A1455%2Fauth%2Fcallback&state={}&simplified_flow=true", "s".repeat(256));
+ for width in [1, 2, 3, 20, 40, 80, 180] {
+ let mut panel = AuthPanel::onboarding("Login to ChatGPT");
+ panel.show_auth_url(url.clone(), None);
+ panel.mount_paste(
+ "Redirect URL:",
+ PastePromptTone::Text,
+ PasteStyle::Visible,
+ false,
+ oneshot::channel().0,
+ );
+ crate::hyperlinks::set_hyperlinks_override(Some(false));
+ let lines = panel.render(&theme(), width, &kb());
+ crate::hyperlinks::set_hyperlinks_override(None);
+ let rows: Vec<String> = lines.iter().map(visible_auth_row).collect();
+ let shown: String = rows[1..]
+ .iter()
+ .take_while(|row| !row.is_empty())
+ .map(|row| row.trim_start())
+ .collect();
+ assert_eq!(shown, url, "width {width}");
+ assert!(lines
+ .iter()
+ .all(|line| crate::width::line_width(line) <= width));
+ if width >= 40 {
+ assert!(rows.iter().any(|row| row.contains("Redirect URL:")));
+ assert!(rows.iter().any(|row| row.contains("cancel")));
+ }
+ let mut clipboard = sink();
+ panel.handle_key("alt+c", &kb(), &mut clipboard);
+ let crate::clipboard::OscSink::Buffer(bytes) = clipboard else {
+ panic!("capture sink")
+ };
+ assert_eq!(
+ String::from_utf8(bytes).unwrap(),
+ crate::osc52::sequence(&url).unwrap()
+ );
+ }
+}
+
+#[test]
+fn every_wrapped_auth_url_row_links_to_the_complete_target() {
+ let url = format!("https://fixture.example/{}", "x".repeat(220));
+ let mut panel = AuthPanel::onboarding("Login");
+ panel.show_auth_url(url.clone(), None);
+ for width in [1, 2, 3, 20, 80, url.len() + 2] {
+ crate::hyperlinks::set_hyperlinks_override(Some(true));
+ let lines = panel.render(&theme(), width, &kb());
+ crate::hyperlinks::set_hyperlinks_override(None);
+ let url_rows: Vec<_> = lines[1..]
+ .iter()
+ .take_while(|line| !line.is_empty())
+ .collect();
+ let text: String = url_rows
+ .iter()
+ .map(|line| visible_auth_row(line).trim_start().to_string())
+ .collect();
+ assert_eq!(text, url);
+ let targets = crate::hyperlinks::frame_link_ranges(&lines);
+ assert_eq!(targets.len(), url_rows.len());
+ for (line, target) in url_rows.iter().zip(targets) {
+ let raw: String = line.iter().map(|span| span.content.as_str()).collect();
+ assert!(raw.ends_with(crate::hyperlinks::OSC8_CLOSE));
+ assert_eq!(target.url, url);
+ assert!(crate::width::line_width(line) <= width);
+ }
+ }
+}
+
+/// Bugbot (cursor) finding: the URL wrap must preserve every byte on screen. `scrub_controls`
+/// spaces control characters and word wrap drops spaces at the break - the visible rows would
+/// no longer match the copied or hyperlinked target. A URL is one token: char-level wrap.
+#[test]
+fn wrapped_auth_url_keeps_spaces_between_the_rows() {
+ let url = format!(
+ "https://example.test/oauth?state={}a{}b{}c",
+ ' ', '\u{1}', ' '
+ );
+ let expected = scrub_controls(&url).replace('\n', "");
+ let mut panel = AuthPanel::onboarding("Login");
+ panel.show_auth_url(url, None);
+ for width in [2, 3, 5, 8, 20, 40] {
+ crate::hyperlinks::set_hyperlinks_override(Some(false));
+ let lines = panel.render(&theme(), width, &kb());
+ crate::hyperlinks::set_hyperlinks_override(None);
+ let mut shown = String::new();
+ for row in &lines[1..] {
+ let raw = visible_auth_row(row);
+ // The URL block ends at the first truly empty row; a wrapped space renders
+ // as a whitespace-only URL row and must not end it.
+ if raw.is_empty() {
+ break;
+ }
+ let segment = if width > 1 {
+ raw.strip_prefix(' ').unwrap_or(&raw)
+ } else {
+ &raw[..]
+ };
+ shown.push_str(segment);
+ }
+ assert_eq!(shown, expected, "width {width}");
+ assert!(lines
+ .iter()
+ .all(|line| crate::width::line_width(line) <= width));
+ }
+}
+
+fn visible_auth_row(line: &Line) -> String {
+ crate::ansi::strip_ansi(
+ &line
+ .iter()
+ .map(|span| span.content.as_str())
+ .collect::<String>(),
+ )
+}
+
+#[test]
+fn wrapped_session_auth_url_keeps_the_link_and_controls_visible() {
+ let url = format!("https://example.test/oauth?state={}", "a".repeat(450));
+ let mut panel = AuthPanel::new("Login to ChatGPT");
+ panel.show_auth_url(url.clone(), None);
+ panel.mount_paste(
+ "Redirect URL:",
+ PastePromptTone::Text,
+ PasteStyle::Visible,
+ false,
+ oneshot::channel().0,
+ );
+ let mut view = crate::view::AgentView::new(theme());
+ view.auth_panel = Some(panel);
+ let rows = view.render_frame(40, 24);
+ let text = rows.iter().map(visible_auth_row).collect::<Vec<_>>();
+ let joined = text.iter().map(|row| row.trim()).collect::<String>();
+ assert!(joined.contains(&url), "complete URL: {text:?}");
+ assert!(
+ joined.contains("Redirect URL:") && joined.contains("cancel"),
+ "controls: {text:?}"
+ );
+}
diff --git a/crates/pa-tui/src/onboarding.rs b/crates/pa-tui/src/onboarding.rs
index 64985c1da8..a3d8eedf1d 100644
--- a/crates/pa-tui/src/onboarding.rs
+++ b/crates/pa-tui/src/onboarding.rs
@@ -273,6 +273,7 @@ impl OnboardingScreen {
kb: &crate::keybindings::KeybindingsManager,
) -> Vec<Line> {
let width = width.max(1);
+ let auth_panel_open = matches!(self.panel.as_ref(), Some(OnboardingPanel::Auth { .. }));
let mut lines: Vec<Line> = vec![Vec::new()];
lines.extend(self.mark_rows(theme, width));
lines.push(Vec::new());
@@ -288,6 +289,15 @@ impl OnboardingScreen {
None => lines.push(Vec::new()),
Some(panel) => lines.extend(panel.render(theme, width, kb)),
}
+ // A long sign-in link can wrap through the splash's fixed logo rows. Yield the logo
+ // first so the full auth block fits whenever the pane can hold it. On a shorter terminal,
+ // keep the block's final input and action rows visible like the session dock does.
+ if auth_panel_open && lines.len() > height {
+ lines.drain(..(LOGO_LINES.len() + 2));
+ if lines.len() > height {
+ lines.drain(..lines.len() - height);
+ }
+ }
while lines.len() < height {
lines.push(Vec::new());
}
@@ -722,6 +732,60 @@ mod tests {
);
}
+ /// When the link wraps, the decorative mark yields its rows to the complete link and the
+ /// action row. A 24-row terminal has room for both once the mark is omitted.
+ #[test]
+ fn wrapped_onboarding_auth_url_keeps_the_link_and_actions_visible() {
+ let mut screen = OnboardingScreen::welcome();
+ screen.mount_panel(crate::onboarding_flow::OnboardingPanel::Auth {
+ panel: std::boxed::Box::new(crate::auth_panel::AuthPanel::onboarding(
+ "Login to Prime Inference",
+ )),
+ heading: Some(crate::onboarding_flow::PRIME_LOGIN_HEADING.to_string()),
+ });
+ let url = format!("https://example.test/oauth?state={}", "a".repeat(450));
+ screen.apply_auth_request(crate::auth_panel::AuthPanelRequest::AuthUrl {
+ url: url.clone(),
+ instructions: None,
+ });
+ screen.apply_auth_request(crate::auth_panel::AuthPanelRequest::PastePrompt {
+ prompt: "Redirect URL:".to_string(),
+ tone: crate::auth_panel::PastePromptTone::Text,
+ style: crate::auth_panel::PasteStyle::Visible,
+ allow_empty: false,
+ reply: tokio::sync::oneshot::channel().0,
+ });
+ let theme = Theme::builtin("prime", ColorMode::TrueColor);
+ let rows = screen.render(&theme, 40, 24, &kb());
+ let text: Vec<String> = rows
+ .iter()
+ .map(|row| {
+ let raw = row
+ .iter()
+ .map(|span| span.content.as_str())
+ .collect::<String>();
+ crate::hyperlinks::strip_osc8_content(&raw)
+ })
+ .collect();
+ let joined = text.iter().map(|row| row.trim()).collect::<String>();
+ assert!(
+ joined.contains(&url),
+ "the complete URL remains visible: {text:?}"
+ );
+ assert!(
+ joined.contains("Redirect URL:"),
+ "the paste prompt remains visible: {text:?}"
+ );
+ assert!(
+ joined.contains("Paste value"),
+ "the paste field remains visible: {text:?}"
+ );
+ assert!(
+ joined.contains("copy") && joined.contains("cancel"),
+ "the URL actions remain visible: {text:?}"
+ );
+ }
+
/// The `SelectTeam` request mounts the onboarding choice question (the brand line returns — no
/// heading) with the personal account first and the teams' slugs as identifiers.
#[test]