mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
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:
1 parent
a8468330bb
commit
76d98a771e
30 files changed
+1317
-44
No files matched your search
@@ -20,6 +20,7 @@ use codex_app_server_protocol::ServerRequest;
|
||||
use codex_app_server_protocol::SessionSource;
|
||||
use codex_app_server_protocol::ThreadReadParams;
|
||||
use codex_app_server_protocol::ThreadReadResponse;
|
||||
use codex_protocol::ThreadId;
|
||||
use codex_protocol::protocol::SubAgentSource;
|
||||
|
||||
impl App {
|
||||
@@ -335,6 +336,13 @@ impl App {
|
||||
let request_id = request_id.clone();
|
||||
let task_request_id = request_id.clone();
|
||||
let source_thread_id = params.thread_id.clone();
|
||||
let inherits_task_tools = params.tool == "fork_thread"
|
||||
&& params
|
||||
.arguments
|
||||
.get("threadId")
|
||||
.and_then(serde_json::Value::as_str)
|
||||
.and_then(|thread_id| ThreadId::from_string(thread_id).ok())
|
||||
.is_none_or(|thread_id| app_server_client.task_tools_available(thread_id));
|
||||
let params = params.clone();
|
||||
let mut thread_start_params =
|
||||
crate::app_server_session::thread_start_params_from_config(
|
||||
@@ -355,6 +363,20 @@ impl App {
|
||||
Some(&app_event_tx),
|
||||
)
|
||||
.await;
|
||||
if inherits_task_tools
|
||||
&& response.success
|
||||
&& let [
|
||||
codex_app_server_protocol::DynamicToolCallOutputContentItem::InputText {
|
||||
text,
|
||||
},
|
||||
] = response.content_items.as_slice()
|
||||
&& let Ok(result) = serde_json::from_str::<serde_json::Value>(text)
|
||||
&& let Some(thread_id) =
|
||||
result.get("threadId").and_then(serde_json::Value::as_str)
|
||||
&& let Ok(thread_id) = ThreadId::from_string(thread_id)
|
||||
{
|
||||
app_event_tx.send(AppEvent::TaskToolsAvailable { thread_id });
|
||||
}
|
||||
app_event_tx.send(AppEvent::DynamicToolCallCompleted {
|
||||
request_id,
|
||||
response,
|
||||
|
||||
@@ -102,12 +102,16 @@ impl App {
|
||||
}
|
||||
AppEvent::DynamicToolThreadStarted {
|
||||
thread_id,
|
||||
task_tools_available,
|
||||
registered,
|
||||
} => {
|
||||
self.agents_overview
|
||||
.dispatched_requests
|
||||
.entry(thread_id)
|
||||
.or_default();
|
||||
if task_tools_available {
|
||||
app_server.remember_task_tool_thread(thread_id);
|
||||
}
|
||||
let _ = registered.send(());
|
||||
}
|
||||
AppEvent::DynamicToolCallCompleted {
|
||||
@@ -129,6 +133,9 @@ impl App {
|
||||
}
|
||||
}
|
||||
}
|
||||
AppEvent::TaskToolsAvailable { thread_id } => {
|
||||
app_server.remember_task_tool_thread(thread_id);
|
||||
}
|
||||
AppEvent::RequestOlderScrollbackHistory { thread_id } => {
|
||||
if self.chat_widget.thread_id() == Some(thread_id)
|
||||
&& self.overlay.is_none()
|
||||
@@ -1158,11 +1165,45 @@ impl App {
|
||||
);
|
||||
}
|
||||
AppEvent::StartFileSearch(query) => {
|
||||
self.file_search.on_user_query(query);
|
||||
self.file_search.on_user_query(query.clone());
|
||||
if let Some(thread_id) = self.active_thread_id
|
||||
&& app_server.task_tools_available(thread_id)
|
||||
&& self.config.features.enabled(Feature::MentionsV2)
|
||||
{
|
||||
let cwd = self
|
||||
.thread_cwd(thread_id)
|
||||
.await
|
||||
.map(|cwd| cwd.to_path_buf())
|
||||
.or_else(|| {
|
||||
app_server
|
||||
.remote_cwd_override()
|
||||
.map(std::path::Path::to_path_buf)
|
||||
})
|
||||
.unwrap_or_else(|| self.config.cwd.to_path_buf());
|
||||
crate::task_mentions::spawn_search(
|
||||
app_server.request_handle(),
|
||||
query,
|
||||
thread_id,
|
||||
cwd,
|
||||
app_server.task_search_generation(),
|
||||
self.app_event_tx.clone(),
|
||||
);
|
||||
}
|
||||
}
|
||||
AppEvent::FileSearchResult { query, matches } => {
|
||||
self.chat_widget.apply_file_search_result(query, matches);
|
||||
}
|
||||
AppEvent::TaskSearchResult {
|
||||
thread_id,
|
||||
query,
|
||||
matches,
|
||||
} => {
|
||||
if self.active_thread_id == Some(thread_id)
|
||||
&& app_server.task_tools_available(thread_id)
|
||||
{
|
||||
self.chat_widget.on_task_search_result(&query, matches);
|
||||
}
|
||||
}
|
||||
AppEvent::RefreshRateLimits { origin } => {
|
||||
self.refresh_rate_limits(app_server, origin);
|
||||
}
|
||||
|
||||
@@ -543,6 +543,8 @@ impl App {
|
||||
/*initial_user_message*/ None,
|
||||
);
|
||||
self.replace_chat_widget(ChatWidget::new_with_app_event(init));
|
||||
self.chat_widget
|
||||
.set_task_mentions_enabled(app_server.task_tools_available(thread_id));
|
||||
self.chat_widget
|
||||
.note_rendered_width(tui.terminal.last_known_screen_size.width);
|
||||
if blocks_direct_input {
|
||||
@@ -638,6 +640,10 @@ impl App {
|
||||
match result {
|
||||
Ok(started) => {
|
||||
let thread_id = started.session.thread_id;
|
||||
if started.task_tools_available {
|
||||
app_server.remember_task_tool_thread(thread_id);
|
||||
self.chat_widget.set_task_mentions_enabled(/*enabled*/ true);
|
||||
}
|
||||
self.pending_primary_events.retain(|event| match event {
|
||||
ThreadBufferedEvent::Notification(notification) => matches!(
|
||||
server_notification_thread_target(notification),
|
||||
@@ -809,6 +815,8 @@ impl App {
|
||||
initial_user_message,
|
||||
);
|
||||
self.replace_chat_widget(ChatWidget::new_with_app_event(init));
|
||||
self.chat_widget
|
||||
.set_task_mentions_enabled(started.task_tools_available);
|
||||
self.chat_widget
|
||||
.note_rendered_width(tui.terminal.last_known_screen_size.width);
|
||||
if started.blocks_direct_input {
|
||||
|
||||
@@ -538,6 +538,8 @@ See the Codex keymap documentation for supported actions and examples."
|
||||
let initial_session_started_at = Instant::now();
|
||||
if let Some(started) = initial_started_thread {
|
||||
let thread_id = started.session.thread_id;
|
||||
app.chat_widget
|
||||
.set_task_mentions_enabled(started.task_tools_available);
|
||||
if started.blocks_direct_input {
|
||||
app.mark_primary_thread_parent_owned(thread_id);
|
||||
}
|
||||
|
||||
@@ -4764,6 +4764,7 @@ async fn primary_thread_ignores_child_mcp_startup_notifications() {
|
||||
session: test_thread_session(child_thread_id, test_path_buf("/tmp/child")),
|
||||
turns: Vec::new(),
|
||||
blocks_direct_input: false,
|
||||
task_tools_available: false,
|
||||
},
|
||||
&mut child_snapshot,
|
||||
)
|
||||
@@ -7652,6 +7653,7 @@ async fn refreshed_snapshot_session_persists_resumed_turns() {
|
||||
session: resumed_session.clone(),
|
||||
turns: resumed_turns.clone(),
|
||||
blocks_direct_input: true,
|
||||
task_tools_available: false,
|
||||
},
|
||||
&mut snapshot,
|
||||
)
|
||||
|
||||
@@ -302,7 +302,8 @@ async fn start_recording_app_server_with_history(
|
||||
AppServerSession::new(
|
||||
app_server,
|
||||
crate::app_server_session::ThreadParamsMode::Embedded,
|
||||
),
|
||||
)
|
||||
.with_startup_config(config),
|
||||
requests,
|
||||
proxy,
|
||||
))
|
||||
@@ -382,7 +383,7 @@ fn spawn_approved_task_tool_call(
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn external_transport_excludes_delegation_dynamic_tools_for_both_start_paths() -> Result<()> {
|
||||
async fn external_transport_registers_dynamic_tools_and_finds_task_mentions() -> Result<()> {
|
||||
let (app, _codex_home) = make_history_test_app().await?;
|
||||
let (mut app_server, requests, proxy) = start_recording_app_server(
|
||||
&app.config,
|
||||
@@ -391,8 +392,10 @@ async fn external_transport_excludes_delegation_dynamic_tools_for_both_start_pat
|
||||
)
|
||||
.await?;
|
||||
|
||||
app_server.start_thread(&app.config).await?;
|
||||
crate::app_server_session::start_thread_with_request_handle(
|
||||
let started = app_server.start_thread(&app.config).await?;
|
||||
assert!(started.task_tools_available);
|
||||
assert!(app_server.task_tools_available(started.session.thread_id));
|
||||
let startup = crate::app_server_session::start_thread_with_request_handle(
|
||||
app_server.request_handle(),
|
||||
app.config.clone(),
|
||||
crate::app_server_session::ThreadParamsMode::Embedded,
|
||||
@@ -400,6 +403,7 @@ async fn external_transport_excludes_delegation_dynamic_tools_for_both_start_pat
|
||||
app_server.thread_tool_transport(),
|
||||
)
|
||||
.await?;
|
||||
assert!(startup.task_tools_available);
|
||||
|
||||
let starts = recorded_params(&requests, "thread/start");
|
||||
assert_eq!(starts.len(), 2);
|
||||
@@ -420,9 +424,68 @@ async fn external_transport_excludes_delegation_dynamic_tools_for_both_start_pat
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
let target_id = started.session.thread_id;
|
||||
app_server
|
||||
.thread_inject_items(target_id, vec![App::side_boundary_prompt_item()])
|
||||
.await?;
|
||||
crate::init_state_db_for_app_server_target(&app.config, &crate::AppServerTarget::Embedded)
|
||||
.await?
|
||||
.expect("state database")
|
||||
.set_thread_preview_if_empty(target_id, "Review database migration")
|
||||
.await
|
||||
.expect("seed searchable thread preview");
|
||||
app_server.shutdown().await?;
|
||||
proxy.await??;
|
||||
let (mut restarted_app_server, _restarted_requests, restarted_proxy) =
|
||||
start_recording_app_server(
|
||||
&app.config,
|
||||
/*blocked_thread_list*/ None,
|
||||
/*failed_thread_name*/ None,
|
||||
)
|
||||
.await?;
|
||||
let resumed = restarted_app_server
|
||||
.resume_thread(
|
||||
app.config.clone(),
|
||||
target_id,
|
||||
crate::app_server_session::ResumeModelSettings::RestoreFromThread,
|
||||
)
|
||||
.await?;
|
||||
assert!(resumed.task_tools_available);
|
||||
assert!(restarted_app_server.task_tools_available(target_id));
|
||||
let forked = restarted_app_server
|
||||
.fork_thread(app.config.clone(), target_id)
|
||||
.await?;
|
||||
assert!(forked.task_tools_available);
|
||||
assert!(restarted_app_server.task_tools_available(forked.session.thread_id));
|
||||
restarted_app_server
|
||||
.thread_set_name(target_id, "Bluebird".to_string())
|
||||
.await?;
|
||||
let (sender, mut events) = tokio::sync::mpsc::unbounded_channel();
|
||||
|
||||
crate::task_mentions::spawn_search(
|
||||
restarted_app_server.request_handle(),
|
||||
"bbd".to_string(),
|
||||
startup.session.thread_id,
|
||||
app.config.cwd.to_path_buf(),
|
||||
restarted_app_server.task_search_generation(),
|
||||
crate::app_event_sender::AppEventSender::new(sender),
|
||||
);
|
||||
|
||||
let event = tokio::time::timeout(Duration::from_secs(/*secs*/ 5), events.recv())
|
||||
.await?
|
||||
.expect("expected task search results");
|
||||
let AppEvent::TaskSearchResult { matches, .. } = event else {
|
||||
panic!("expected task search results");
|
||||
};
|
||||
assert!(
|
||||
matches
|
||||
.iter()
|
||||
.any(|task| task.thread_id == target_id.to_string() && task.title == "Bluebird"),
|
||||
"expected created task in {matches:?}"
|
||||
);
|
||||
|
||||
restarted_app_server.shutdown().await?;
|
||||
restarted_proxy.await??;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -453,12 +516,11 @@ async fn local_daemon_registers_approval_gated_mcp_tools_for_both_start_paths()
|
||||
)
|
||||
.await?;
|
||||
|
||||
let thread_id = app_server
|
||||
.start_thread(&app.config)
|
||||
.await?
|
||||
.session
|
||||
.thread_id;
|
||||
crate::app_server_session::start_thread_with_request_handle(
|
||||
let started = app_server.start_thread(&app.config).await?;
|
||||
let thread_id = started.session.thread_id;
|
||||
assert!(started.task_tools_available);
|
||||
assert!(app_server.task_tools_available(thread_id));
|
||||
let startup = crate::app_server_session::start_thread_with_request_handle(
|
||||
app_server.request_handle(),
|
||||
app.config.clone(),
|
||||
crate::app_server_session::ThreadParamsMode::Embedded,
|
||||
@@ -466,6 +528,7 @@ async fn local_daemon_registers_approval_gated_mcp_tools_for_both_start_paths()
|
||||
app_server.thread_tool_transport(),
|
||||
)
|
||||
.await?;
|
||||
assert!(startup.task_tools_available);
|
||||
|
||||
let inventory: codex_app_server_protocol::ListMcpServerStatusResponse = app_server
|
||||
.request_handle()
|
||||
@@ -631,11 +694,13 @@ async fn local_daemon_registers_approval_gated_mcp_tools_for_both_start_paths()
|
||||
};
|
||||
let AppEvent::DynamicToolThreadStarted {
|
||||
thread_id: child_thread_id,
|
||||
task_tools_available,
|
||||
registered,
|
||||
} = registration
|
||||
else {
|
||||
panic!("expected the MCP-created task to register")
|
||||
};
|
||||
assert!(task_tools_available);
|
||||
assert!(registered.send(()).is_ok());
|
||||
let created = creation.await??;
|
||||
assert!(created.status().is_success());
|
||||
@@ -769,8 +834,10 @@ async fn older_external_server_starts_without_unsupported_dynamic_tools_or_histo
|
||||
)
|
||||
.await?;
|
||||
|
||||
app_server.start_thread(&app.config).await?;
|
||||
crate::app_server_session::start_thread_with_request_handle(
|
||||
let started = app_server.start_thread(&app.config).await?;
|
||||
assert!(!started.task_tools_available);
|
||||
assert!(!app_server.task_tools_available(started.session.thread_id));
|
||||
let startup = crate::app_server_session::start_thread_with_request_handle(
|
||||
app_server.request_handle(),
|
||||
app.config.clone(),
|
||||
crate::app_server_session::ThreadParamsMode::Embedded,
|
||||
@@ -778,6 +845,7 @@ async fn older_external_server_starts_without_unsupported_dynamic_tools_or_histo
|
||||
app_server.thread_tool_transport(),
|
||||
)
|
||||
.await?;
|
||||
assert!(!startup.task_tools_available);
|
||||
|
||||
let starts = recorded_params(&requests, "thread/start");
|
||||
assert_eq!(starts.len(), 6);
|
||||
@@ -1065,6 +1133,7 @@ async fn dynamic_tool_requests_ignore_other_namespaces_and_dispatch_tui_namespac
|
||||
.expect("background task registration event");
|
||||
let AppEvent::DynamicToolThreadStarted {
|
||||
thread_id: created_thread_id,
|
||||
task_tools_available,
|
||||
registered,
|
||||
} = registration
|
||||
else {
|
||||
@@ -1076,6 +1145,7 @@ async fn dynamic_tool_requests_ignore_other_namespaces_and_dispatch_tui_namespac
|
||||
&mut app_server,
|
||||
AppEvent::DynamicToolThreadStarted {
|
||||
thread_id: created_thread_id,
|
||||
task_tools_available,
|
||||
registered,
|
||||
},
|
||||
)
|
||||
@@ -1085,6 +1155,7 @@ async fn dynamic_tool_requests_ignore_other_namespaces_and_dispatch_tui_namespac
|
||||
.dispatched_requests
|
||||
.contains_key(&created_thread_id)
|
||||
);
|
||||
assert!(app_server.task_tools_available(created_thread_id));
|
||||
let AppEvent::DynamicToolCallCompleted { response, .. } =
|
||||
tokio::time::timeout(std::time::Duration::from_secs(/*secs*/ 5), events.recv())
|
||||
.await?
|
||||
@@ -1143,6 +1214,7 @@ async fn dynamic_tool_requests_ignore_other_namespaces_and_dispatch_tui_namespac
|
||||
);
|
||||
let AppEvent::DynamicToolThreadStarted {
|
||||
thread_id: continued_thread_id,
|
||||
task_tools_available,
|
||||
registered,
|
||||
} = tokio::time::timeout(std::time::Duration::from_secs(/*secs*/ 5), events.recv())
|
||||
.await?
|
||||
@@ -1157,6 +1229,7 @@ async fn dynamic_tool_requests_ignore_other_namespaces_and_dispatch_tui_namespac
|
||||
&mut app_server,
|
||||
AppEvent::DynamicToolThreadStarted {
|
||||
thread_id: continued_thread_id,
|
||||
task_tools_available,
|
||||
registered,
|
||||
},
|
||||
)
|
||||
|
||||
@@ -696,6 +696,7 @@ async fn fresh_startup_thread_drains_buffered_approval_before_draft_handoff() ->
|
||||
session: test_thread_session(thread_id, test_path_buf("/tmp/project")),
|
||||
turns: Vec::new(),
|
||||
blocks_direct_input: false,
|
||||
task_tools_available: false,
|
||||
}),
|
||||
},
|
||||
))
|
||||
@@ -910,6 +911,7 @@ async fn startup_thread_started_submits_queued_startup_input() {
|
||||
session: test_thread_session(thread_id, test_path_buf("/tmp/project")),
|
||||
turns: Vec::new(),
|
||||
blocks_direct_input: false,
|
||||
task_tools_available: false,
|
||||
}),
|
||||
)
|
||||
.await
|
||||
@@ -998,6 +1000,7 @@ async fn startup_thread_started_discards_another_threads_buffered_events() {
|
||||
session: test_thread_session(thread_id, test_path_buf("/tmp/project")),
|
||||
turns: Vec::new(),
|
||||
blocks_direct_input: false,
|
||||
task_tools_available: false,
|
||||
}),
|
||||
)
|
||||
.await
|
||||
@@ -1046,6 +1049,7 @@ async fn startup_thread_started_does_not_replay_resolved_approval() -> Result<()
|
||||
session: test_thread_session(thread_id, test_path_buf("/tmp/project")),
|
||||
turns: Vec::new(),
|
||||
blocks_direct_input: false,
|
||||
task_tools_available: false,
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
@@ -1177,6 +1181,7 @@ fn stale_startup_thread_started_removes_local_routing_state() -> Result<()> {
|
||||
session: test_thread_session(stale_thread_id, test_path_buf("/tmp/project")),
|
||||
turns: Vec::new(),
|
||||
blocks_direct_input: false,
|
||||
task_tools_available: false,
|
||||
}),
|
||||
)
|
||||
.await?;
|
||||
|
||||
Reference in new issue
Block a user