Add task mentions to the TUI composer (#40315)

## What changed

- Include matching Codex tasks in the `@` mention popup when the active thread supports task tools, prioritizing tasks from the current working directory.
- Submit selected tasks as bounded live thread references so Codex can load their contents with `read_thread`.
- Preserve task mentions across composer history and thread start, resume, and fork flows.

## Testing

- Add coverage for task search and capability propagation, popup selection and rendering, submission encoding, history round-trips, and reference validation and limits.

GitOrigin-RevId: 17502be91bf6d4b01745668829eb69fb318cb5b9
This commit is contained in:
Eric Traut authored and copyberry committed 2026-08-24 02:46:56 +00:00
1 parent a8468330bb
commit 76d98a771e
30 files changed
+1317 -44

No files matched your search

@@ -3,6 +3,18 @@
use super::*;
impl ChatWidget {
pub(crate) fn set_task_mentions_enabled(&mut self, enabled: bool) {
self.bottom_pane.set_task_mentions_enabled(enabled);
}
pub(crate) fn on_task_search_result(
&mut self,
query: &str,
matches: Vec<crate::task_mentions::TaskMention>,
) {
self.bottom_pane.on_task_search_result(query, matches);
}
pub(super) fn user_message_from_submission(
&mut self,
text: String,
@@ -143,8 +155,12 @@ impl ChatWidget {
local_images,
remote_image_urls,
text_elements,
mention_bindings,
mut mention_bindings,
} = user_message;
if !self.bottom_pane.task_mentions_enabled() {
mention_bindings
.retain(|binding| crate::task_mentions::valid_thread_path(&binding.path).is_none());
}
let render_in_history = !self.turn_lifecycle.agent_turn_running;
let mut items: Vec<UserInput> = Vec::new();
@@ -310,6 +326,7 @@ impl ChatWidget {
}
self.maybe_apply_ide_context(&mut items);
crate::task_mentions::apply_task_references(&mut items, &mention_bindings, self.thread_id);
let collaboration_mode = if self.collaboration_modes_enabled() {
self.active_collaboration_mask
@@ -387,22 +404,26 @@ impl ChatWidget {
path: binding.path.clone(),
})
.collect::<Vec<_>>();
let history_text = match &history_record {
let history = match &history_record {
UserMessageHistoryRecord::UserMessageText if !submitted_message.text.is_empty() => {
Some(encode_history_mentions(
Some((
&submitted_message.text,
&encoded_mentions,
submitted_message.text_elements.as_slice(),
))
}
UserMessageHistoryRecord::Override(history) if !history.text.is_empty() => {
Some(encode_history_mentions(&history.text, &encoded_mentions))
Some((&history.text, history.text_elements.as_slice()))
}
UserMessageHistoryRecord::UserMessageText | UserMessageHistoryRecord::Override(_) => {
None
}
};
if let Some(history_text) = history_text {
self.append_message_history_entry(history_text);
if let Some((text, elements)) = history {
self.append_message_history_entry(encode_history_mentions_at_elements(
text,
&encoded_mentions,
elements,
));
}
if let Some(pending_steer) = pending_steer {
@@ -0,0 +1,5 @@
---
source: tui/src/chatwidget/tests/composer_submission.rs
expression: rendered
---
› Inspect @Review database migration
@@ -2163,6 +2163,104 @@ fn user_message_display_from_inputs_hides_prompt_context() {
);
}
#[test]
fn task_and_plugin_mentions_with_same_name_keep_prompt_order() {
let task = "[@same](thread://task-123)";
let items = [
UserInput::Text {
text: format!("{task} @same"),
text_elements: [0..task.len(), task.len() + 1..task.len() + 6]
.into_iter()
.map(|range| TextElement::new(range.into(), Some("@same".to_string())).into())
.collect(),
},
UserInput::Mention {
name: "same".to_string(),
path: "plugin://same@test".to_string(),
},
];
assert_eq!(
mention_bindings_from_user_inputs(&items, "@same @same"),
["thread://task-123", "plugin://same@test"].map(|path| MentionBinding {
sigil: '@',
mention: "same".to_string(),
path: path.to_string(),
})
);
let split_items = [
UserInput::Text {
text: format!("Task {task} "),
text_elements: vec![
TextElement::new((5..5 + task.len()).into(), Some("@same".to_string())).into(),
],
},
UserInput::Text {
text: "@same".to_string(),
text_elements: vec![TextElement::new((0..5).into(), Some("@same".to_string())).into()],
},
items[1].clone(),
];
assert_eq!(
mention_bindings_from_user_inputs(&split_items, "Task @same @same"),
mention_bindings_from_user_inputs(&items, "@same @same")
);
}
#[tokio::test]
async fn task_mention_submission_and_transcript_preserve_the_visible_title() {
for enabled in [false, true] {
let (mut chat, mut events, mut ops) = make_chatwidget_manual(/*model_override*/ None).await;
chat.thread_id = Some(ThreadId::new());
chat.set_task_mentions_enabled(enabled);
let title = "Review database migration";
chat.submit_user_message(UserMessage {
text: format!("Inspect @{title}"),
local_images: Vec::new(),
remote_image_urls: Vec::new(),
text_elements: vec![TextElement::new(
("Inspect ".len().."Inspect @".len() + title.len()).into(),
Some(format!("@{title}")),
)],
mention_bindings: vec![MentionBinding {
sigil: '@',
mention: title.to_string(),
path: "thread://task-123".to_string(),
}],
});
let Op::UserTurn { items, .. } = next_submit_op(&mut ops) else {
panic!("expected user turn");
};
if !enabled {
assert!(matches!(items.as_slice(), [UserInput::Text { text, .. }]
if text == "Inspect @Review database migration"));
continue;
}
assert!(matches!(items.as_slice(), [UserInput::Text { text, .. }]
if text.contains("MUST call `read_thread`")
&& text.contains("\"threadId\":\"task-123\"")
&& text.ends_with("Inspect [@Review database migration](thread://task-123)")));
assert_eq!(
mention_bindings_from_user_inputs(&items, &format!("Inspect @{title}")),
vec![MentionBinding {
sigil: '@',
mention: title.to_string(),
path: "thread://task-123".to_string(),
}]
);
complete_user_message_for_inputs(&mut chat, "user-task-reference", items);
let rendered = drain_insert_history(&mut events)
.into_iter()
.flatten()
.map(|line| line.to_string())
.collect::<Vec<_>>()
.join("\n");
assert_chatwidget_snapshot!("task_mention_transcript", rendered);
}
}
#[tokio::test]
async fn committed_user_message_with_hidden_prompt_context_renders_local_images() {
let (mut chat, mut rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
+53 -1
View File
@@ -596,8 +596,58 @@ pub(crate) fn mention_bindings_from_user_inputs(
| UserInput::LocalAudio { .. } => None,
})
.collect();
for item in items {
let UserInput::Text {
text,
text_elements,
} = item
else {
continue;
};
for element in text_elements {
if let Some((mention, path, end)) =
crate::task_mentions::parse_task_link(text, element.byte_range.start)
&& end == element.byte_range.end
&& element
.placeholder()
.and_then(|placeholder| placeholder.strip_prefix('@'))
== Some(mention.as_str())
{
mention_bindings.push(MentionBinding {
sigil: '@',
mention,
path,
});
}
}
}
mention_bindings.sort_by_key(|binding| {
mention_start(binding.sigil, &binding.mention).unwrap_or(usize::MAX)
let token = if crate::task_mentions::valid_thread_path(&binding.path).is_some() {
crate::task_mentions::format_task_link(&binding.mention, &binding.path)
} else {
format!("{}{}", binding.sigil, binding.mention)
};
let mut text_offset = 0;
items
.iter()
.find_map(|item| {
let UserInput::Text {
text,
text_elements,
} = item
else {
return None;
};
let offset = text_offset;
text_offset += text.len();
text_elements.iter().find_map(|element| {
(text.get(element.byte_range.start..element.byte_range.end)
== Some(token.as_str()))
.then_some(offset + element.byte_range.start)
})
})
.or_else(|| mention_start(binding.sigil, &binding.mention))
.unwrap_or(usize::MAX)
});
mention_bindings
}
@@ -714,6 +764,8 @@ impl ChatWidget {
}
}
(message, text_elements) = crate::task_mentions::decode_task_links(&message, text_elements);
Self::user_message_display_from_parts(
message,
text_elements,