[2 of 3] Support long pasted text in TUI goals (#27509)

## Stack

1. [1 of 3] Support long raw TUI goal objectives - #27508
2. **[2 of 3] Support long pasted text in TUI goals** - this PR
3. [3 of 3] Support images in TUI goals - #27510

## Why

Large text pasted into the TUI composer is represented as a paste
placeholder plus pending paste metadata. For `/goal`, preserving only
the visible placeholder is not enough: the agent would see a short
placeholder string instead of the actual pasted text, and the long-text
support from the first PR would never see the payload.

The TUI also needs to avoid writing stale sidecar files when a user
pastes a large block and then deletes its placeholder before submitting
the goal.

## What Changed

- Introduces a TUI `GoalDraft` for goal submissions so `/goal`, `/goal
edit`, and queued goal commands can carry objective text plus text
elements and pending paste payloads.
- Materializes active pasted-text placeholders to `pasted-text-N.txt`
files through the app-server filesystem path introduced in #27508.
- Rewrites active paste placeholders in the persisted objective to file
references, while leaving literal placeholder-looking text alone.
- Filters out deleted paste placeholders so otherwise-small goals do not
require `$CODEX_HOME` or remote filesystem writes.
- Preserves pending paste metadata when a `/goal` command is queued
before a thread exists.

## Verification

- Added goal materialization tests for active paste placeholders,
deleted paste placeholders, and whitespace-only paste payloads.
- Added/updated TUI slash-command tests for large pasted text, queued
`/goal` commands before thread start, and queued oversized goal
behavior.

## Manual Testing

- Used real terminal bracketed-paste sequences through a remote TUI
session. A 1,228-byte multiline paste became `pasted-text-1.txt`; its
first/last lines and byte count matched exactly, and the persisted
objective referenced the server-host path.
- Pasted a large block, deleted its placeholder, and submitted a small
replacement objective. No new directory or sidecar file was created.
- Added two same-length large pastes to one goal. The composer
disambiguated their visible placeholders, and materialization preserved
order and contents in `pasted-text-1.txt` and `pasted-text-2.txt`.
- Submitted a whitespace-only large paste and verified the goal was
rejected as empty without writing a file.
- Submitted a pasted-text replacement while another goal was active,
verified no file was written before confirmation, then canceled and
confirmed the original goal remained unchanged.
- Combined a large paste with enough raw text to exceed 4,000 characters
after placeholder rewriting. The paste sidecar and `goal-objective.md`
were created in the same remote attachment directory, and `/goal edit`
restored the rewritten objective with its sidecar reference.
This commit is contained in:
Eric Traut authored and GitHub committed 2026-06-12 15:34:04 -07:00
1 parent 216dee1189
commit c0f1ec5afd
17 files changed
+600 -201

No files matched your search

+42 -3
View File
@@ -189,6 +189,7 @@ use super::mentions_v2::MentionV2Popup;
use super::mentions_v2::MentionV2Selection;
use super::paste_burst::CharDecision;
use super::paste_burst::PasteBurst;
use super::prompt_args::parse_slash_name;
use super::skill_popup::MentionItem;
use super::skill_popup::SkillPopup;
use super::slash_commands::BuiltinCommandFlags;
@@ -279,6 +280,7 @@ pub enum InputResult {
text: String,
text_elements: Vec<TextElement>,
action: QueuedInputAction,
pending_pastes: Vec<(String, String)>,
},
/// A bare slash command parsed by the composer.
///
@@ -303,6 +305,12 @@ pub enum QueuedInputAction {
RunShell,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
enum PendingPasteHandling {
Expand,
Preserve,
}
/// Feature flags for reusing the chat composer in other bottom-pane surfaces.
///
/// The default keeps today's behavior intact. Other call sites can opt out of
@@ -2611,13 +2619,18 @@ impl ChatComposer {
&mut self,
record_history: bool,
) -> Option<(String, Vec<TextElement>)> {
self.prepare_submission_text_with_options(record_history, SlashValidation::Immediate)
self.prepare_submission_text_with_options(
record_history,
SlashValidation::Immediate,
PendingPasteHandling::Expand,
)
}
fn prepare_submission_text_with_options(
&mut self,
record_history: bool,
slash_validation: SlashValidation,
pending_paste_handling: PendingPasteHandling,
) -> Option<(String, Vec<TextElement>)> {
let mut text = self.current_text();
let original_input = text.clone();
@@ -2631,7 +2644,9 @@ impl ChatComposer {
self.draft.textarea.set_text_clearing_elements("");
self.draft.is_bash_mode = false;
if !self.draft.pending_pastes.is_empty() {
if pending_paste_handling == PendingPasteHandling::Expand
&& !self.draft.pending_pastes.is_empty()
{
// Expand placeholders so element byte ranges stay aligned.
let (expanded, expanded_elements) =
Self::expand_pending_pastes(&text, text_elements, &self.draft.pending_pastes);
@@ -2700,7 +2715,11 @@ impl ChatComposer {
local_image_paths: self.attachments.local_image_paths(),
remote_image_urls: self.attachments.remote_image_urls(),
mention_bindings: original_mention_bindings,
pending_pastes: Vec::new(),
pending_pastes: if pending_paste_handling == PendingPasteHandling::Preserve {
original_pending_pastes.clone()
} else {
Vec::new()
},
});
}
self.draft.pending_pastes.clear();
@@ -2739,6 +2758,15 @@ impl ChatComposer {
}
let raw_text = self.draft.textarea.text();
let defer_slash_validation = self.slash_input().should_parse_on_dequeue(raw_text);
let preserve_pending_pastes = defer_slash_validation
&& !self.draft.pending_pastes.is_empty()
&& parse_slash_name(raw_text)
.is_some_and(|(name, _, _)| name == SlashCommand::Goal.command());
let pending_pastes = if preserve_pending_pastes {
self.draft.pending_pastes.clone()
} else {
Vec::new()
};
if let Some((text, text_elements)) = self.prepare_submission_text_with_options(
/*record_history*/ true,
if defer_slash_validation {
@@ -2746,6 +2774,11 @@ impl ChatComposer {
} else {
SlashValidation::Immediate
},
if preserve_pending_pastes {
PendingPasteHandling::Preserve
} else {
PendingPasteHandling::Expand
},
) {
let action = slash_input::queued_input_action(&text, defer_slash_validation);
return (
@@ -2753,6 +2786,7 @@ impl ChatComposer {
text,
text_elements,
action,
pending_pastes,
},
true,
);
@@ -2824,6 +2858,7 @@ impl ChatComposer {
text,
text_elements,
action: QueuedInputAction::Plain,
pending_pastes: Vec::new(),
},
true,
)
@@ -7279,6 +7314,7 @@ mod tests {
text: "hi".to_string(),
text_elements: Vec::new(),
action: QueuedInputAction::Plain,
pending_pastes: Vec::new(),
}
);
assert!(composer.draft.textarea.text().is_empty());
@@ -8306,6 +8342,7 @@ mod tests {
text: "queued before session".to_string(),
text_elements: Vec::new(),
action: QueuedInputAction::Plain,
pending_pastes: Vec::new(),
}
);
}
@@ -8337,6 +8374,7 @@ mod tests {
text,
text_elements,
action,
..
} => {
assert_eq!(text, input);
assert!(text_elements.is_empty());
@@ -8514,6 +8552,7 @@ mod tests {
text,
text_elements,
action,
..
} => {
assert_eq!(text, expected_text);
assert!(text_elements.is_empty());