mirror of
https://github.com/openai/codex.git
synced 2026-11-27 23:31:09 +00:00
Use the shared composer in the agent command center (#42428)
## What changed - Replace the command center's single-line new-task input with the shared chat composer, including multiline editing, paste handling, Vim mode, configured keybindings, cursor behavior, and input validation. - Keep task drafts and editor state across dashboard refreshes and reconnects while separating composer focus from list, search, and rename actions. - Preserve whitespace in dispatched task prompts, block submission while offline, and restore unsent prompts after dispatch failures when the composer is still available. ## Testing - Add coverage for focus routing, draft retention, multiline pastes, custom keybindings, Vim mode, offline editing, failed-dispatch recovery, and responsive rendering. GitOrigin-RevId: a609ae95d497cbae0ebcac4cdcc50fe49d74832a
This commit is contained in:
1 parent
cac96cd7b1
commit
62f553bfd0
20 files changed
+717
-145
No files matched your search
@@ -1,5 +1,8 @@
|
||||
//! Dashboard for inspecting and managing the TUI's retained daemon tasks.
|
||||
//! The shared view state retains the new-task editor across metadata refreshes.
|
||||
|
||||
#[path = "agents_overview_input.rs"]
|
||||
mod input;
|
||||
#[path = "agents_overview_render.rs"]
|
||||
mod render;
|
||||
|
||||
@@ -7,6 +10,8 @@ use super::agents_overview::AGENTS_OVERVIEW_VIEW_ID;
|
||||
use crate::app_event::AppEvent;
|
||||
use crate::app_event_sender::AppEventSender;
|
||||
use crate::bottom_pane::BottomPaneView;
|
||||
use crate::bottom_pane::CancellationEvent;
|
||||
use crate::bottom_pane::ChatComposer;
|
||||
use crate::bottom_pane::ViewCompletion;
|
||||
use crate::key_hint::KeyBindingListExt;
|
||||
use crate::key_hint::ShortcutHint;
|
||||
@@ -85,9 +90,13 @@ pub(super) struct AgentsOverviewRow {
|
||||
pub(super) is_current: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
#[derive(Default)]
|
||||
pub(super) struct AgentsOverviewViewState {
|
||||
// Search and rename never borrow the new-task draft.
|
||||
pub(super) input: String,
|
||||
pub(super) composer: Option<ChatComposer>,
|
||||
pub(super) key_chord_hint: Option<Vec<(String, String)>>,
|
||||
pub(super) focus: AgentsOverviewFocus,
|
||||
pub(super) connection_notice: Option<&'static str>,
|
||||
search: String,
|
||||
searching: bool,
|
||||
@@ -97,6 +106,40 @@ pub(super) struct AgentsOverviewViewState {
|
||||
pub(super) completion: Option<ViewCompletion>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Default, PartialEq, Eq)]
|
||||
pub(super) enum AgentsOverviewFocus {
|
||||
#[default]
|
||||
Composer,
|
||||
List,
|
||||
}
|
||||
|
||||
impl AgentsOverviewViewState {
|
||||
pub(super) fn focus_composer(&mut self) {
|
||||
self.focus = AgentsOverviewFocus::Composer;
|
||||
if let Some(composer) = self.composer.as_mut() {
|
||||
composer.resume_text_entry();
|
||||
}
|
||||
}
|
||||
|
||||
fn editing_metadata(&self) -> bool {
|
||||
self.searching || self.renaming
|
||||
}
|
||||
|
||||
fn composing(&self) -> bool {
|
||||
self.focus == AgentsOverviewFocus::Composer && !self.searching && !self.renaming
|
||||
}
|
||||
|
||||
fn composer_owns_escape(&self) -> bool {
|
||||
self.composer.as_ref().is_some_and(|composer| {
|
||||
composer.popup_active()
|
||||
|| (composer.is_vim_enabled()
|
||||
&& !composer
|
||||
.keymap_contexts()
|
||||
.contains(KeymapContext::VimNormal))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) struct AgentsOverviewView {
|
||||
pub(super) rows: Vec<AgentsOverviewRow>,
|
||||
selected: usize,
|
||||
@@ -105,6 +148,8 @@ pub(super) struct AgentsOverviewView {
|
||||
app_event_tx: AppEventSender,
|
||||
keymap: ListKeymap,
|
||||
agents_keymap: AgentsKeymap,
|
||||
composer_hints: Vec<(String, String)>,
|
||||
composer_keymap: crate::keymap::ComposerKeymap,
|
||||
}
|
||||
|
||||
impl AgentsOverviewView {
|
||||
@@ -120,6 +165,18 @@ impl AgentsOverviewView {
|
||||
.and_then(|thread_id| rows.iter().position(|row| row.thread_id == thread_id))
|
||||
.or_else(|| rows.iter().position(|row| row.is_current))
|
||||
.unwrap_or(0);
|
||||
let composer_hints = [
|
||||
(KeymapContext::Composer, "submit", "create task"),
|
||||
(KeymapContext::Editor, "insert_newline", "newline"),
|
||||
]
|
||||
.into_iter()
|
||||
.filter_map(|(context, action, label)| {
|
||||
keymap
|
||||
.primary_hint(context, action)
|
||||
.map(|hint| (hint.display_label().replace(" + ", "+"), label.to_string()))
|
||||
})
|
||||
.chain([("esc".to_string(), "tasks".to_string())])
|
||||
.collect();
|
||||
let mut view = Self {
|
||||
rows,
|
||||
selected,
|
||||
@@ -128,6 +185,8 @@ impl AgentsOverviewView {
|
||||
app_event_tx,
|
||||
keymap: keymap.list,
|
||||
agents_keymap: keymap.agents,
|
||||
composer_hints,
|
||||
composer_keymap: keymap.composer,
|
||||
};
|
||||
view.state().completion = None;
|
||||
let visible = view.visible_indices();
|
||||
@@ -200,37 +259,23 @@ impl AgentsOverviewView {
|
||||
}
|
||||
|
||||
fn activate(&mut self) {
|
||||
let state = self.state().clone();
|
||||
let input = state.input.clone();
|
||||
if !state.searching && !input.is_empty() && input.trim().is_empty() {
|
||||
return;
|
||||
}
|
||||
if !state.searching && !input.trim().is_empty() {
|
||||
if state.renaming {
|
||||
if let Some(row) = self.selected_row() {
|
||||
self.app_event_tx
|
||||
.send(AppEvent::RenameAgentsOverviewThread {
|
||||
thread_id: row.thread_id,
|
||||
name: input.trim().to_string(),
|
||||
});
|
||||
}
|
||||
self.state().renaming = false;
|
||||
} else {
|
||||
let input = self.state().input.clone();
|
||||
if self.state().renaming && !input.trim().is_empty() {
|
||||
if let Some(row) = self.selected_row() {
|
||||
self.app_event_tx
|
||||
.send(AppEvent::DispatchAgentsOverviewTask {
|
||||
prompt: input,
|
||||
cwd: (!state.status_grouping)
|
||||
.then(|| self.selected_row().map(|row| row.thread.cwd.clone()))
|
||||
.flatten(),
|
||||
.send(AppEvent::RenameAgentsOverviewThread {
|
||||
thread_id: row.thread_id,
|
||||
name: input.trim().to_string(),
|
||||
});
|
||||
}
|
||||
self.state().renaming = false;
|
||||
self.state().input.clear();
|
||||
} else if let Some(row) = self.selected_row().filter(|_| !state.renaming) {
|
||||
} else if let Some(row) = self.selected_row().filter(|_| !self.state().renaming) {
|
||||
self.app_event_tx
|
||||
.send(AppEvent::SelectAgentsOverviewThread {
|
||||
thread_id: row.thread_id,
|
||||
});
|
||||
if state.searching {
|
||||
if self.state().searching {
|
||||
let mut state = self.state();
|
||||
state.search.clear();
|
||||
state.searching = false;
|
||||
@@ -404,6 +449,10 @@ impl AgentsOverviewView {
|
||||
}
|
||||
|
||||
impl BottomPaneView for AgentsOverviewView {
|
||||
fn next_frame_delay(&self) -> Option<std::time::Duration> {
|
||||
self.state().composer.as_ref()?.footer_flash_delay()
|
||||
}
|
||||
|
||||
fn view_id(&self) -> Option<&'static str> {
|
||||
Some(AGENTS_OVERVIEW_VIEW_ID)
|
||||
}
|
||||
@@ -413,7 +462,15 @@ impl BottomPaneView for AgentsOverviewView {
|
||||
}
|
||||
|
||||
fn keymap_contexts(&self) -> KeymapContextSet {
|
||||
KeymapContextSet::new(KeymapContext::List).with(KeymapContext::Agents)
|
||||
let state = self.state();
|
||||
if state.composing() {
|
||||
state
|
||||
.composer
|
||||
.as_ref()
|
||||
.map_or_else(KeymapContextSet::default, ChatComposer::keymap_contexts)
|
||||
} else {
|
||||
KeymapContextSet::new(KeymapContext::List).with(KeymapContext::Agents)
|
||||
}
|
||||
}
|
||||
|
||||
fn completion(&self) -> Option<ViewCompletion> {
|
||||
@@ -428,13 +485,63 @@ impl BottomPaneView for AgentsOverviewView {
|
||||
true
|
||||
}
|
||||
|
||||
fn on_ctrl_c(&mut self) -> CancellationEvent {
|
||||
let mut state = self.state();
|
||||
if state.editing_metadata() {
|
||||
state.searching = false;
|
||||
state.renaming = false;
|
||||
state.search.clear();
|
||||
state.input.clear();
|
||||
return CancellationEvent::Handled;
|
||||
}
|
||||
if let Some(composer) = state.composer.as_mut()
|
||||
&& (composer.cancel_vim_search()
|
||||
|| composer.cancel_history_search()
|
||||
|| composer.clear_for_ctrl_c().is_some())
|
||||
{
|
||||
return CancellationEvent::Handled;
|
||||
}
|
||||
CancellationEvent::NotHandled
|
||||
}
|
||||
|
||||
fn handle_paste(&mut self, pasted: String) -> bool {
|
||||
self.edit_input(|input| {
|
||||
input.push_str(&crate::history_cell::sanitize_user_text(pasted.into()))
|
||||
})
|
||||
if self.state().editing_metadata() {
|
||||
return self.edit_input(|input| {
|
||||
input.push_str(&crate::history_cell::sanitize_user_text(pasted.into()))
|
||||
});
|
||||
}
|
||||
let mut state = self.state();
|
||||
if state.focus == AgentsOverviewFocus::List {
|
||||
state.focus_composer();
|
||||
}
|
||||
state
|
||||
.composer
|
||||
.as_mut()
|
||||
.is_some_and(|composer| composer.handle_paste(pasted))
|
||||
}
|
||||
|
||||
fn flush_paste_burst_if_due(&mut self) -> bool {
|
||||
self.state()
|
||||
.composer
|
||||
.as_mut()
|
||||
.is_some_and(ChatComposer::flush_paste_burst_if_due)
|
||||
}
|
||||
|
||||
fn is_in_paste_burst(&self) -> bool {
|
||||
self.state()
|
||||
.composer
|
||||
.as_ref()
|
||||
.is_some_and(ChatComposer::is_in_paste_burst)
|
||||
}
|
||||
|
||||
fn handle_key_event(&mut self, key: KeyEvent) {
|
||||
if key.kind == crossterm::event::KeyEventKind::Release {
|
||||
return;
|
||||
}
|
||||
if self.state().composing() {
|
||||
self.handle_composer_key(key);
|
||||
return;
|
||||
}
|
||||
if key.code == KeyCode::Backspace
|
||||
&& key.modifiers.is_empty()
|
||||
&& self.keymap.action_for(key).is_none()
|
||||
@@ -447,8 +554,20 @@ impl BottomPaneView for AgentsOverviewView {
|
||||
if is_plain_text_key_event(key)
|
||||
&& let KeyCode::Char(character) = key.code
|
||||
{
|
||||
self.edit_input(|input| input.push(character));
|
||||
return;
|
||||
if self.state().editing_metadata() {
|
||||
self.edit_input(|input| input.push(character));
|
||||
return;
|
||||
}
|
||||
if !self
|
||||
.state()
|
||||
.composer
|
||||
.as_ref()
|
||||
.is_some_and(ChatComposer::is_vim_enabled)
|
||||
{
|
||||
self.state().focus_composer();
|
||||
self.handle_composer_key(key);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if self.agents_keymap.search.is_pressed(key) || {
|
||||
@@ -467,7 +586,8 @@ impl BottomPaneView for AgentsOverviewView {
|
||||
return;
|
||||
}
|
||||
|
||||
if self.state().connection_notice.is_some() {
|
||||
if self.state().connection_notice.is_some() && !self.agents_keymap.new_task.is_pressed(key)
|
||||
{
|
||||
match self.keymap.action_for(key) {
|
||||
Some(ListAction::MoveUp) => self.move_selection(/*forward*/ false),
|
||||
Some(ListAction::MoveDown) => self.move_selection(/*forward*/ true),
|
||||
@@ -491,6 +611,7 @@ impl BottomPaneView for AgentsOverviewView {
|
||||
state.searching = false;
|
||||
state.renaming = false;
|
||||
state.input.clear();
|
||||
state.focus_composer();
|
||||
return;
|
||||
}
|
||||
if self.agents_keymap.rename.is_pressed(key) {
|
||||
|
||||
Reference in new issue
Block a user