Render assistant file citations as local links (#42650)

## What changed

- Convert `codex-file-citation` directives in assistant Markdown into local-file links while preserving paths with Markdown-significant characters, Unicode, Windows separators, and location suffixes.
- Apply citation rendering consistently to streaming output, finalized messages and plans, and resume-picker transcript previews.
- Keep directives literal in code, HTML, existing links, reference definitions, escaped text, and generic Markdown rendering.
- Bound repeated parsing work for malformed directive candidates without limiting valid citations.

## Testing

- Add coverage for citation parsing and rendering across finalized, streaming, and resume-preview output, including malformed input and path edge cases.

GitOrigin-RevId: 5a0bfb3fc7ac21b7e8846fd170a349fb2d2d5e85
This commit is contained in:
Ian MacLeod authored and copyberry committed 2026-09-04 01:46:55 +00:00
1 parent 956aa3f637
commit f46671b14a
13 files changed
+635 -22

No files matched your search

@@ -92,6 +92,22 @@ fn finalized_markdown_reuses_lines_primed_by_transcript_height() {
);
}
#[test]
fn finalized_assistant_file_citation_renders_as_local_path_snapshot() {
let cwd = std::env::temp_dir();
let output = cwd.join("Quarterly Report.xlsx").display().to_string();
let cell = AgentMarkdownCell::new(
format!(
r#"Generated :codex-file-citation{{artifact_kind="workbook" path="{output}" purpose="output"}}."#
),
&cwd,
);
let rendered = ratatui::text::Text::from(cell.display_lines(/*width*/ 80));
insta::assert_snapshot!(rendered, @"• Generated Quarterly Report.xlsx.");
}
#[test]
fn finalized_markdown_cache_misses_when_width_or_render_style_changes() {
let cell = AgentMarkdownCell::new("finalized **markdown**".to_string(), Path::new("/tmp"));
@@ -20,3 +20,19 @@ fn finalized_plan_reuses_lines_primed_by_transcript_height() {
vec![Line::from("cached")]
);
}
#[test]
fn finalized_plan_file_citation_renders_as_local_path_snapshot() {
let cwd = std::env::temp_dir();
let output = cwd.join("Quarterly Report.xlsx").display().to_string();
let plan = new_proposed_plan(
format!(
"- :codex-file-citation{{path=\"{output}\" purpose=\"output\" artifact_kind=\"workbook\"}}\n"
),
&cwd,
);
let rendered = ratatui::text::Text::from(plan.display_lines(/*width*/ 80));
insta::assert_snapshot!(rendered, @"• Proposed Plan\n \n \n - Quarterly Report.xlsx");
}