Preserve tool authority for TUI delegation prompts (#41046)

## Why

Delegated prompts should retain the authority of the TUI tool that sent them instead of being recorded as user input.

## What changed

- Start delegated `create_thread` and `send_message_to_thread` turns with a namespaced tool output and an empty user input list.
- Recognize delegated outputs from trusted Codex namespaces when building activity summaries.
- Render replayed delegation outputs in history and transcripts with their source task attribution, without adding them to composer history.

## Testing

- Cover turn request encoding, namespace filtering, activity summaries, and replayed history/transcript rendering.

GitOrigin-RevId: aeb2f5c8ad2f2a898c80e8fc791ed879a0ab655d
This commit is contained in:
Eric Traut authored and copyberry committed 2026-08-27 04:51:46 +00:00
1 parent 57e2edc6e9
commit 72c96598c6
7 files changed
+180 -22

No files matched your search

+21 -1
View File
@@ -218,7 +218,27 @@ impl ChatWidget {
ThreadItem::ContextCompaction { .. } => {
self.add_info_message("Context compacted".to_string(), /*hint*/ None);
}
ThreadItem::HookPrompt { .. } | ThreadItem::FunctionCallOutput { .. } => {}
ThreadItem::FunctionCallOutput {
name,
namespace,
output,
..
} => {
if let Some((source_thread_id, prompt)) =
crate::dynamic_tools::parse_delegated_tool_output(
&name,
namespace.as_deref(),
&output,
)
{
self.add_to_history(history_cell::PrefixedWrappedHistoryCell::new(
format!("Sent by Codex from task {source_thread_id}\n{prompt}"),
"• ".dim(),
" ",
));
}
}
ThreadItem::HookPrompt { .. } => {}
ThreadItem::CollabAgentToolCall {
id,
tool,
@@ -0,0 +1,6 @@
---
source: tui/src/chatwidget/tests/history_replay.rs
expression: "lines_to_single_string(&cells[0])"
---
• Sent by Codex from task source-task
Follow <up> & report
@@ -2,6 +2,7 @@ use super::*;
use crate::app_event::HistoryLookupResponse;
use codex_app_server_protocol::NetworkAccess;
use codex_app_server_protocol::SandboxPolicy;
use codex_protocol::models::FunctionCallOutputBody;
use codex_protocol::models::ManagedFileSystemPermissions;
use codex_protocol::permissions::FileSystemAccessMode;
use codex_protocol::permissions::FileSystemPath;
@@ -275,6 +276,49 @@ async fn replayed_review_prompt_does_not_seed_composer_history() {
assert_eq!(chat.bottom_pane.composer_text(), "");
}
#[tokio::test]
async fn replayed_delegated_tool_output_is_attributed_without_seeding_composer_history() {
let (mut chat, mut rx, _ops) = make_chatwidget_manual(/*model_override*/ None).await;
let item = AppServerThreadItem::FunctionCallOutput {
id: "delegation-1".to_string(),
name: "send_message_to_thread".to_string(),
namespace: Some("codex_tui".to_string()),
output: FunctionCallOutputBody::Text(
"<codex_delegation>\n <source_thread_id>source-task</source_thread_id>\n <input>Follow &lt;up&gt; &amp; report</input>\n</codex_delegation>".to_string(),
),
};
chat.replay_thread_item(
item.clone(),
"turn-1".to_string(),
ReplayKind::ResumeInitialMessages,
);
let cells = drain_insert_history(&mut rx);
assert_eq!(cells.len(), 1);
assert_chatwidget_snapshot!(
"replayed_delegated_tool_output",
lines_to_single_string(&cells[0])
);
let projected = crate::thread_transcript::thread_items_to_transcript_cells(
/*thread_id*/ None,
&chat.config.cwd,
[item],
crate::thread_transcript::RawReasoningVisibility::Hidden,
/*config*/ None,
);
assert_eq!(
projected
.iter()
.map(|cell| lines_to_single_string(&cell.transcript_lines(/*width*/ 80)))
.collect::<Vec<_>>(),
vec![lines_to_single_string(&cells[0])]
);
chat.handle_key_event(KeyEvent::new(KeyCode::Up, KeyModifiers::NONE));
assert_eq!(chat.bottom_pane.composer_text(), "");
}
#[tokio::test]
async fn replayed_nested_review_prompts_do_not_render_or_seed_composer_history() {
let (mut chat, mut rx, _ops) = make_chatwidget_manual(/*model_override*/ None).await;