Add TUI tools for managing Codex tasks (#40308)

## Why

The TUI rejected app-server dynamic tool calls as unsupported, so agents could
not inspect or manage other Codex tasks through a TUI session.

## What changed

- Add the `codex_tui` tool namespace for listing, reading, waiting on, creating,
  forking, messaging, renaming, archiving, and restoring tasks.
- Handle tool calls through existing app-server thread operations, with bounded
  inputs and responses and cleanup when calls complete or the TUI disconnects.
- Route delegation tools through an authenticated local MCP server with explicit
  approval prompts, while respecting configured and managed MCP policies.
- Fall back to starting threads without dynamic tools when connected to an older
  app server that does not support them.

## Testing

Add coverage for tool schemas and response bounds, task lifecycle operations,
approval-gated MCP transport, namespace dispatch, cancellation, and legacy
app-server fallback behavior.

GitOrigin-RevId: c782c11f0a3edceb3fa6909a4b92d6ce01a6eed3
This commit is contained in:
Eric Traut authored and copyberry committed 2026-08-24 01:50:53 +00:00
1 parent fb0781b9ee
commit a8468330bb
18 files changed
+3722 -62

No files matched your search

+20
View File
@@ -28,12 +28,14 @@ fn spawn_startup_thread_start(
let request_handle = app_server.request_handle();
let thread_params_mode = app_server.thread_params_mode();
let remote_cwd_override = app_server.remote_cwd_override().map(Path::to_path_buf);
let thread_tool_transport = app_server.thread_tool_transport();
tokio::spawn(async move {
let result = crate::app_server_session::start_thread_with_request_handle(
request_handle,
config,
thread_params_mode,
remote_cwd_override,
thread_tool_transport,
)
.await
.map_err(|err| format!("{err:#}"));
@@ -177,6 +179,22 @@ impl App {
if let Some(updated_model) = config.model.clone() {
model = updated_model;
}
let dynamic_tool_status_updates = tokio::sync::broadcast::channel(/*capacity*/ 64).0;
if matches!(&app_server_target, AppServerTarget::LocalDaemon { .. })
&& !crate::uses_remote_workspace_or_environment(
&app_server_target,
environment_manager.as_ref(),
)
&& let Err(error) = app_server
.start_dynamic_tool_mcp(
config.clone(),
app_event_tx.clone(),
dynamic_tool_status_updates.clone(),
)
.await
{
tracing::warn!(%error, "TUI task delegation is unavailable without its MCP server");
}
let model_catalog = Arc::new(ModelCatalog::new(available_models.clone()));
let feedback_audience = bootstrap.feedback_audience;
let auth_mode = bootstrap.auth_mode;
@@ -501,6 +519,8 @@ See the Codex keymap documentation for supported actions and examples."
primary_session_configured: None,
pending_primary_events: VecDeque::new(),
pending_app_server_requests: PendingAppServerRequests::default(),
dynamic_tool_status_updates,
dynamic_tool_tasks: HashMap::new(),
pending_startup_thread_start,
startup_protected_input_boundary: true,
startup_pending_protected_request: false,