mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Render inline visualization links in the TUI (#33925)
## Why
Assistant-authored inline visualizations need a terminal fallback that lets users open generated artifacts in a browser.
## What changed
- Recognize `::codex-inline-vis{file="..."}` directives in assistant Markdown and replace them with browser links during streaming, finalized history rendering, and local transcript previews.
- Materialize visualization fragments in sandboxed viewer documents with a content security policy, while restricting artifacts to HTML files within the thread's visualization directory and limiting their size.
- Show an explicit unavailable message for invalid or missing artifacts, hide incomplete streaming directives, and preserve directive text in code blocks and user Markdown.
- Add a trusted file-link path for generated viewers without enabling arbitrary `file:` links in Markdown.
## Testing
Add coverage for directive rewriting, streaming and replay, artifact validation, sandboxed viewer generation, trusted terminal hyperlinks, and literal preservation.
GitOrigin-RevId: a666b4ebc82bb5798ad45bd137fd815d538e1de2
This commit is contained in:
1 parent
97dbd01a3d
commit
f896ab9f25
23 files changed
+2123
-106
No files matched your search
@@ -365,6 +365,7 @@ impl HistoryCell for AgentMessageCell {
|
||||
pub(crate) struct AgentMarkdownCell {
|
||||
markdown_source: String,
|
||||
cwd: PathBuf,
|
||||
inline_visualization_context: Option<crate::inline_visualization::InlineVisualizationContext>,
|
||||
}
|
||||
|
||||
impl AgentMarkdownCell {
|
||||
@@ -373,10 +374,26 @@ impl AgentMarkdownCell {
|
||||
/// `markdown_source` must be the raw source accumulated by the stream controller, not already
|
||||
/// wrapped terminal lines. Passing rendered lines here would make future resize reflow preserve
|
||||
/// stale wrapping instead of repairing it.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn new(markdown_source: String, cwd: &Path) -> Self {
|
||||
Self::new_with_inline_visualizations(
|
||||
markdown_source,
|
||||
cwd,
|
||||
/*inline_visualization_context*/ None,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn new_with_inline_visualizations(
|
||||
markdown_source: String,
|
||||
cwd: &Path,
|
||||
inline_visualization_context: Option<
|
||||
crate::inline_visualization::InlineVisualizationContext,
|
||||
>,
|
||||
) -> Self {
|
||||
Self {
|
||||
markdown_source,
|
||||
cwd: cwd.to_path_buf(),
|
||||
inline_visualization_context,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -399,10 +416,11 @@ impl HistoryCell for AgentMarkdownCell {
|
||||
|
||||
// Re-render markdown from source at the current width. Reserve 2 columns for the "• " /
|
||||
// " " prefix prepended below.
|
||||
let lines = crate::markdown::render_markdown_agent_with_links_and_cwd(
|
||||
let lines = crate::markdown::render_markdown_agent_with_links_cwd_and_visualizations(
|
||||
&self.markdown_source,
|
||||
Some(wrap_width),
|
||||
Some(self.cwd.as_path()),
|
||||
self.inline_visualization_context.as_ref(),
|
||||
);
|
||||
prefix_hyperlink_lines(lines, "• ".dim(), " ".into())
|
||||
}
|
||||
|
||||
@@ -349,10 +349,10 @@ fn composite_cell_preserves_child_web_links() {
|
||||
|
||||
assert_eq!(
|
||||
lines[2].hyperlinks,
|
||||
vec![crate::terminal_hyperlinks::TerminalHyperlink {
|
||||
columns: 0..destination.len(),
|
||||
destination: destination.to_string(),
|
||||
}]
|
||||
vec![crate::terminal_hyperlinks::TerminalHyperlink::web(
|
||||
/*columns*/ 0..destination.len(),
|
||||
destination.to_string(),
|
||||
)]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user