feat(tui/branch): include hidden preface with auto-submitted task instructing agent to ask for confirmation and optionally merge+cleanup on success

This commit is contained in:
James Peter
2025-09-08 10:36:37 +10:00
parent a78a225644
commit 16b7800501
2 changed files with 18 additions and 1 deletions
+2 -1
View File
@@ -872,7 +872,8 @@ impl App<'_> {
if let AppState::Chat { widget } = &mut self.app_state {
if let Some(prompt) = initial_prompt {
if !prompt.is_empty() {
widget.submit_text_message(prompt);
let preface = "[internal] When you finish this task, ask the user if they want any changes. If they are happy, offer to merge the branch back into the repository's default branch and delete the worktree. Wait for explicit confirmation before merging.".to_string();
widget.submit_text_message_with_preface(prompt, preface);
}
}
}
+16
View File
@@ -5627,6 +5627,22 @@ impl ChatWidget<'_> {
self.submit_user_message(text.into());
}
/// Submit a visible text message, but prepend a hidden instruction that is
/// sent to the agent in the same turn. The hidden text is not added to the
/// chat history; only `visible` appears to the user.
pub(crate) fn submit_text_message_with_preface(&mut self, visible: String, preface: String) {
if visible.is_empty() { return; }
use crate::chatwidget::message::UserMessage;
use codex_core::protocol::InputItem;
let mut ordered = Vec::new();
if !preface.trim().is_empty() {
ordered.push(InputItem::Text { text: preface });
}
ordered.push(InputItem::Text { text: visible.clone() });
let msg = UserMessage { display_text: visible, ordered_items: ordered };
self.submit_user_message(msg);
}
pub(crate) fn token_usage(&self) -> &TokenUsage {
&self.total_token_usage
}