Keep pasted text inline in TUI goals (#61690)

## Why

Pasted goal text was stored in separate files, leaving file references in the goal editor instead of the pasted content.

## What changed

Expand pending pastes into the goal objective before processing image attachments and checking the objective length. Short goals now retain their text inline; oversized expanded objectives still use the managed `goal-objective.md` file.

## Testing

Update goal tests to cover oversized Unicode pastes, inline text without new attachment files, and pastes combined with image attachments. Add a snapshot showing `Use hello` when reopening a pasted goal in the editor.

GitOrigin-RevId: afd8e8de1ca12fe81bdfd526a0ad9e92a43addc2
This commit is contained in:
Eric Traut
2026-11-15 20:50:29 +00:00
committed by copyberry
parent 375a6b1653
commit 9017fd33f3
3 changed files with 49 additions and 48 deletions
@@ -0,0 +1,9 @@
---
source: tui/src/app/tests.rs
expression: "render_bottom_popup(&app.chat_widget, 80)"
---
Edit goal
› Use hello
enter submit · esc back
+34 -16
View File
@@ -9380,13 +9380,20 @@ async fn set_thread_goal_draft_materializes_long_objective_and_confirms_before_p
let thread_id = started.session.thread_id;
app.enqueue_primary_thread_session(started.session, started.turns)
.await?;
let objective = "x".repeat(MAX_THREAD_GOAL_OBJECTIVE_CHARS + 1);
let long_paste = "한글".repeat(MAX_THREAD_GOAL_OBJECTIVE_CHARS / 2);
let long_placeholder = "[Pasted Content 4000 chars]";
let objective = format!("Prefix {long_paste} suffix");
app.set_thread_goal_draft(
&mut app_server,
thread_id,
crate::goal_files::GoalDraft {
objective: objective.clone(),
objective: format!("Prefix {long_placeholder} suffix"),
text_elements: vec![TextElement::new(
(7..7 + long_placeholder.len()).into(),
Some(long_placeholder.to_string()),
)],
pending_pastes: vec![(long_placeholder.to_string(), long_paste)],
..Default::default()
},
crate::app_event::ThreadGoalSetMode::ConfirmIfExists,
@@ -9472,13 +9479,17 @@ async fn set_thread_goal_draft_materializes_long_objective_and_confirms_before_p
.await?
.goal
.expect("replacement goal should be set");
let paste_path = goal
.objective
.strip_prefix("Use pasted text file: ")
.and_then(|text| text.strip_suffix(". Read this file before continuing."))
.expect("paste file reference");
assert_eq!(std::fs::read_to_string(paste_path)?, "hello");
let attachment_count = std::fs::read_dir(&attachments_dir)?.count();
assert_eq!(goal.objective, "Use hello");
assert_eq!(
std::fs::read_dir(&attachments_dir)?.count(),
attachment_count
);
app.open_thread_goal_editor(&mut app_server, Some(thread_id))
.await;
insta::assert_snapshot!(
"pasted_goal_editor",
render_bottom_popup(&app.chat_widget, /*width*/ 80)
);
let stale_paste = (placeholder.to_string(), "hello".to_string());
app.set_thread_goal_draft(
@@ -9535,11 +9546,19 @@ async fn set_thread_goal_draft_materializes_long_objective_and_confirms_before_p
&mut app_server,
thread_id,
crate::goal_files::GoalDraft {
objective: format!("Describe {image_placeholder}"),
text_elements: vec![TextElement::new(
(9..9 + image_placeholder.len()).into(),
Some(image_placeholder.to_string()),
)],
objective: format!("Describe {placeholder} {image_placeholder}"),
text_elements: vec![
TextElement::new(
(9..9 + placeholder.len()).into(),
Some(placeholder.to_string()),
),
TextElement::new(
(10 + placeholder.len()..10 + placeholder.len() + image_placeholder.len())
.into(),
Some(image_placeholder.to_string()),
),
],
pending_pastes: vec![(placeholder.to_string(), "hello".to_string())],
local_images: vec![crate::bottom_pane::LocalImageAttachment {
placeholder: image_placeholder.to_string(),
path: image_path,
@@ -9548,7 +9567,6 @@ async fn set_thread_goal_draft_materializes_long_objective_and_confirms_before_p
"https://example.com/first.png".to_string(),
"https://example.com/second.png".to_string(),
],
..Default::default()
},
crate::app_event::ThreadGoalSetMode::ReplaceExisting,
)
@@ -9560,7 +9578,7 @@ async fn set_thread_goal_draft_materializes_long_objective_and_confirms_before_p
.expect("image goal should be set")
.objective;
let copied_image = objective
.strip_prefix("Describe image file: ")
.strip_prefix("Describe hello image file: ")
.and_then(|text| text.split_once("\n\n"))
.map(|(path, _)| path)
.expect("copied image path");
+6 -32
View File
@@ -1,4 +1,4 @@
//! Materializes oversized TUI goal objectives, pastes, and images as app-server-host files.
//! Expands pasted goal text and materializes oversized objectives and images as app-server-host files.
use std::fs;
use std::path::Path;
@@ -37,21 +37,14 @@ pub(crate) async fn materialize_goal_draft(
codex_home: Option<&GoalFilePath>,
draft: GoalDraft,
) -> Result<(String, Option<GoalFilePath>)> {
let mut objective = draft.objective;
let (mut objective, text_elements) = ChatComposer::expand_pending_pastes(
&draft.objective,
draft.text_elements,
&draft.pending_pastes,
);
if objective.trim().is_empty() {
bail!("Goal objective must not be empty.");
}
let text_elements = draft.text_elements;
if !draft.pending_pastes.is_empty() {
let (expanded_objective, _) = ChatComposer::expand_pending_pastes(
&objective,
text_elements.clone(),
&draft.pending_pastes,
);
if expanded_objective.trim().is_empty() {
bail!("Goal objective must not be empty.");
}
}
let mut active_placeholders = text_elements
.iter()
@@ -60,25 +53,6 @@ pub(crate) async fn materialize_goal_draft(
.collect::<Vec<_>>();
let mut output_dir = None;
let mut replacements = Vec::new();
for (placeholder, text) in draft.pending_pastes.iter() {
let Some(active_idx) = active_placeholders
.iter()
.position(|active| *active == placeholder.as_str())
else {
continue;
};
active_placeholders.swap_remove(active_idx);
let path = ensure_goal_output_dir(app_server, codex_home, &mut output_dir)
.await?
.join(format!("pasted-text-{}.txt", replacements.len() + 1));
write_attachment(app_server, path.clone(), text.as_bytes().to_vec()).await?;
replacements.push((
placeholder.clone(),
format!("pasted text file: {path}. Read this file before continuing."),
));
}
let mut image_lines = Vec::new();
for (idx, image) in draft.local_images.iter().enumerate() {
if !image.placeholder.is_empty() {