mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Normalize whitespace-only lines in agent messages (#34772)
## What changed Apply the existing whitespace-only line normalization to both streaming and finalized agent Markdown. Blank lines now discard indentation and stale hyperlinks while preserving their line style. GitOrigin-RevId: f6150190b02f8cd8c853220cae1a2dcd2f4578a5
This commit is contained in:
1 parent
9ee63da142
commit
c00e2e851c
6 files changed
+33
-26
No files matched your search
+1
-1
@@ -5,7 +5,7 @@ expression: "rendered.lines.iter().map(rendered_line_text).collect::<Vec<_>>().j
|
|||||||
latest user question
|
latest user question
|
||||||
|
|
||||||
• Final answer:
|
• Final answer:
|
||||||
|
|
||||||
Pattern Outcome
|
Pattern Outcome
|
||||||
━━━━━━━━━━━━ ━━━━━━━━━━━
|
━━━━━━━━━━━━ ━━━━━━━━━━━
|
||||||
Table tail Preserved
|
Table tail Preserved
|
||||||
+1
-1
@@ -5,7 +5,7 @@ expression: "rendered.lines.iter().map(rendered_line_text).collect::<Vec<_>>().j
|
|||||||
latest user question
|
latest user question
|
||||||
|
|
||||||
• Final answer:
|
• Final answer:
|
||||||
|
|
||||||
Pattern Outcome
|
Pattern Outcome
|
||||||
━━━━━━━━━━━━ ━━━━━━━━━━━
|
━━━━━━━━━━━━ ━━━━━━━━━━━
|
||||||
Table tail Preserved
|
Table tail Preserved
|
||||||
@@ -407,6 +407,21 @@ impl AgentMarkdownCell {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn normalize_whitespace_only_hyperlink_lines(mut lines: Vec<HyperlinkLine>) -> Vec<HyperlinkLine> {
|
||||||
|
for line in &mut lines {
|
||||||
|
if line
|
||||||
|
.line
|
||||||
|
.spans
|
||||||
|
.iter()
|
||||||
|
.all(|span| span.content.chars().all(char::is_whitespace))
|
||||||
|
{
|
||||||
|
line.line = Line::default().style(line.line.style);
|
||||||
|
line.hyperlinks.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lines
|
||||||
|
}
|
||||||
|
|
||||||
impl HistoryCell for AgentMarkdownCell {
|
impl HistoryCell for AgentMarkdownCell {
|
||||||
fn display_lines(&self, width: u16) -> Vec<Line<'static>> {
|
fn display_lines(&self, width: u16) -> Vec<Line<'static>> {
|
||||||
visible_lines(self.display_hyperlink_lines(width))
|
visible_lines(self.display_hyperlink_lines(width))
|
||||||
@@ -432,7 +447,11 @@ impl HistoryCell for AgentMarkdownCell {
|
|||||||
Some(self.cwd.as_path()),
|
Some(self.cwd.as_path()),
|
||||||
self.inline_visualization_context.as_ref(),
|
self.inline_visualization_context.as_ref(),
|
||||||
);
|
);
|
||||||
prefix_hyperlink_lines(lines, "• ".dim(), " ".into())
|
normalize_whitespace_only_hyperlink_lines(prefix_hyperlink_lines(
|
||||||
|
lines,
|
||||||
|
"• ".dim(),
|
||||||
|
" ".into(),
|
||||||
|
))
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(rendered_lines) = &self.rendered_lines {
|
if let Some(rendered_lines) = &self.rendered_lines {
|
||||||
@@ -487,7 +506,7 @@ impl HistoryCell for StreamingAgentTailCell {
|
|||||||
fn display_hyperlink_lines(&self, _width: u16) -> Vec<HyperlinkLine> {
|
fn display_hyperlink_lines(&self, _width: u16) -> Vec<HyperlinkLine> {
|
||||||
// Tail lines are already rendered at the controller's current stream width.
|
// Tail lines are already rendered at the controller's current stream width.
|
||||||
// Re-wrapping them here can split table borders and produce malformed in-flight rows.
|
// Re-wrapping them here can split table borders and produce malformed in-flight rows.
|
||||||
let mut lines = prefix_hyperlink_lines(
|
normalize_whitespace_only_hyperlink_lines(prefix_hyperlink_lines(
|
||||||
self.lines.clone(),
|
self.lines.clone(),
|
||||||
if self.is_first_line {
|
if self.is_first_line {
|
||||||
"• ".dim()
|
"• ".dim()
|
||||||
@@ -495,19 +514,7 @@ impl HistoryCell for StreamingAgentTailCell {
|
|||||||
" ".into()
|
" ".into()
|
||||||
},
|
},
|
||||||
" ".into(),
|
" ".into(),
|
||||||
);
|
))
|
||||||
for line in &mut lines {
|
|
||||||
if line
|
|
||||||
.line
|
|
||||||
.spans
|
|
||||||
.iter()
|
|
||||||
.all(|span| span.content.chars().all(char::is_whitespace))
|
|
||||||
{
|
|
||||||
line.line = Line::default().style(line.line.style);
|
|
||||||
line.hyperlinks.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lines
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn transcript_hyperlink_lines(&self, width: u16) -> Vec<HyperlinkLine> {
|
fn transcript_hyperlink_lines(&self, width: u16) -> Vec<HyperlinkLine> {
|
||||||
|
|||||||
+4
-4
@@ -9,11 +9,11 @@ rich before:
|
|||||||
|
|
||||||
• - first item
|
• - first item
|
||||||
- second item
|
- second item
|
||||||
|
|
||||||
Col Value
|
Col Value
|
||||||
━━━━━━ ━━━━━━━
|
━━━━━━ ━━━━━━━
|
||||||
code x = 1
|
code x = 1
|
||||||
|
|
||||||
copy me
|
copy me
|
||||||
• Called
|
• Called
|
||||||
└ workspace.inspect({"path":"README.md
|
└ workspace.inspect({"path":"README.md
|
||||||
@@ -45,11 +45,11 @@ rich after:
|
|||||||
|
|
||||||
• - first item
|
• - first item
|
||||||
- second item
|
- second item
|
||||||
|
|
||||||
Col Value
|
Col Value
|
||||||
━━━━━━ ━━━━━━━
|
━━━━━━ ━━━━━━━
|
||||||
code x = 1
|
code x = 1
|
||||||
|
|
||||||
copy me
|
copy me
|
||||||
• Called
|
• Called
|
||||||
└ workspace.inspect({"path":"README.md
|
└ workspace.inspect({"path":"README.md
|
||||||
|
|||||||
+3
-3
@@ -3,9 +3,9 @@ source: tui/src/inline_visualization_tests.rs
|
|||||||
expression: text
|
expression: text
|
||||||
---
|
---
|
||||||
• Fenced:
|
• Fenced:
|
||||||
|
|
||||||
::codex-inline-vis{file="chart.html"}
|
::codex-inline-vis{file="chart.html"}
|
||||||
|
|
||||||
Indented:
|
Indented:
|
||||||
|
|
||||||
::codex-inline-vis{file="chart.html"}
|
::codex-inline-vis{file="chart.html"}
|
||||||
+2
-2
@@ -3,8 +3,8 @@ source: tui/src/inline_visualization_tests.rs
|
|||||||
expression: snapshot_text
|
expression: snapshot_text
|
||||||
---
|
---
|
||||||
• Before
|
• Before
|
||||||
|
|
||||||
Open chart visualization in the browser
|
Open chart visualization in the browser
|
||||||
file://<viewer-path>
|
file://<viewer-path>
|
||||||
|
|
||||||
After
|
After
|
||||||
Reference in new issue
Block a user