Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions codex-rs/config/src/tui_keymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ impl KeybindingsSpec {
#[serde(deny_unknown_fields)]
#[schemars(deny_unknown_fields)]
pub struct TuiGlobalKeymap {
/// Prefix for persistent, context-aware shortcut menus.
pub leader: Option<KeybindingsSpec>,
/// Open the shared agent-session overview.
pub open_agents: Option<KeybindingsSpec>,
/// Open the transcript overlay.
Expand Down Expand Up @@ -594,6 +596,17 @@ fn normalize_keybinding_spec(raw: &str) -> Result<String, String> {
));
}

if strokes[0].eq_ignore_ascii_case("leader") {
let [_, completion] = strokes.as_slice() else {
return Err(format!(
"invalid keybinding `{raw}`: `leader` must be followed by one key \
(for example `leader c`)."
));
};
return normalize_keybinding_stroke(completion)
.map(|completion| format!("leader {completion}"));
}

strokes
.into_iter()
.map(normalize_keybinding_stroke)
Expand Down
10 changes: 10 additions & 0 deletions codex-rs/core/config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4712,6 +4712,7 @@
"copy": null,
"find_transcript": null,
"focus_activity": null,
"leader": null,
"open_agents": null,
"open_external_editor": null,
"open_transcript": null,
Expand Down Expand Up @@ -5515,6 +5516,14 @@
],
"description": "Focus activity groups in the owned transcript to inspect their details."
},
"leader": {
"allOf": [
{
"$ref": "#/definitions/KeybindingsSpec"
}
],
"description": "Prefix for persistent, context-aware shortcut menus."
},
"open_agents": {
"allOf": [
{
Expand Down Expand Up @@ -5710,6 +5719,7 @@
"copy": null,
"find_transcript": null,
"focus_activity": null,
"leader": null,
"open_agents": null,
"open_external_editor": null,
"open_transcript": null,
Expand Down
1 change: 1 addition & 0 deletions codex-rs/core/tests/suite/mcp_executor_context_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ async fn thread_projection_preserves_executor_order_and_unavailable_selections()
vec![unavailable.clone(), ready.clone()],
vec![ready.clone(), unavailable.clone()],
] {
// These synthetic executor selections have no capability roots.
let selections = requests
.iter()
.cloned()
Expand Down
2 changes: 2 additions & 0 deletions codex-rs/ext/extension-api/tests/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ fn mcp_context_preserves_selected_executor_order_and_unavailability() {
workspace_roots: Vec::new(),
selected_capability_roots: Default::default(),
config: EnvironmentConfigState::Pending,
selected_capability_roots: Default::default(),
},
TurnEnvironmentSelection {
environment_id: "ready-secondary".to_owned(),
cwd: PathUri::parse("file:///other").expect("workspace URI"),
workspace_roots: Vec::new(),
selected_capability_roots: Default::default(),
config: EnvironmentConfigState::FromThread,
selected_capability_roots: Default::default(),
},
];
let context = McpServerContributionContext::global(&config);
Expand Down
4 changes: 3 additions & 1 deletion codex-rs/tui/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,9 @@ impl App {
self.handle_draw_pre_render(tui, screen_size)?;
}

if matches!(&event, TuiEvent::Paste(_) | TuiEvent::FocusLost) {
if matches!(&event, TuiEvent::Paste(_) | TuiEvent::FocusLost)
|| matches!(&event, TuiEvent::Mouse(mouse) if mouse.kind != crossterm::event::MouseEventKind::Moved)
{
self.cancel_pending_key_chord();
}

Expand Down
24 changes: 18 additions & 6 deletions codex-rs/tui/src/app/agents_overview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use super::agents_overview_view::AgentsOverviewView;
use super::session_lifecycle::ThreadAttachPresentation;
use super::*;
use crate::app_event::AgentsOverviewThreadRefresh;
use crate::bottom_pane::BottomPaneView;
use crate::bottom_pane::SelectionDescriptionLayout;
use crate::bottom_pane::SelectionItem;
use crate::bottom_pane::SelectionViewParams;
Expand Down Expand Up @@ -281,6 +282,11 @@ impl App {
else {
return;
};
let previous_thread_id = self
.agents_overview
.visible_thread_ids
.get(selected)
.copied();
let selected_thread_id = self
.agents_overview
.view_state
Expand All @@ -292,12 +298,7 @@ impl App {
&& !self.agents_overview.hidden_threads.contains(id)
})
.or(self.agents_overview.selection_after_removal.take())
.or_else(|| {
self.agents_overview
.visible_thread_ids
.get(selected)
.copied()
});
.or(previous_thread_id);
let threads = self
.agents_overview
.threads
Expand All @@ -307,6 +308,17 @@ impl App {
.collect();
let view = self.agents_overview_view(threads, selected_thread_id);
self.agents_overview.visible_thread_ids = view.thread_ids();
let next_thread_id = view
.selected_index()
.and_then(|index| self.agents_overview.visible_thread_ids.get(index).copied());
if (previous_thread_id.is_none() || previous_thread_id != next_thread_id)
&& self
.chat_widget
.selected_index_for_active_view(AGENTS_OVERVIEW_VIEW_ID)
.is_some()
{
self.cancel_pending_key_chord();
}
if let Ok(mut state) = self.agents_overview.view_state.lock()
&& state
.rename_target
Expand Down
6 changes: 6 additions & 0 deletions codex-rs/tui/src/app/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ impl App {
tui: &mut tui::Tui,
key_event: KeyEvent,
) -> Option<KeyEvent> {
if self.chat_widget.take_key_chord_reset() {
self.cancel_pending_key_chord();
}
self.transcript_view.set_keymap_bindings(&self.keymap);
if let Some(Overlay::Transcript(overlay)) = &mut self.overlay {
overlay.set_keymap_bindings(&self.keymap);
Expand Down Expand Up @@ -174,6 +177,9 @@ impl App {
}

pub(super) fn expire_pending_key_chord(&mut self) {
if self.chat_widget.take_key_chord_reset() {
self.cancel_pending_key_chord();
}
let contexts = self.active_keymap_contexts();
if self.key_chord_matcher.expire(contexts) {
self.set_key_chord_hint_override(/*items*/ None);
Expand Down
2 changes: 1 addition & 1 deletion codex-rs/tui/src/app/tests/realtime_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ async fn voice_mute_shortcut_reaches_the_active_widget() -> Result<()> {
app.handle_tui_event(
&mut tui,
&mut server,
tui::TuiEvent::Key(KeyEvent::new(KeyCode::Char('x'), KeyModifiers::CONTROL)),
tui::TuiEvent::Key(KeyEvent::new(KeyCode::F(9), KeyModifiers::NONE)),
)
.await?;
// The fixture has no microphone handle, so reaching mute reports that limitation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Other task:

gpt-test default · /tmp/project
Restored owner:
voice ● listening ⌃x mute /voice stop
voice ● listening f9 mute /voice stop
mic ▁▁▁▁▁▁ codex ▁▁▁▁▁▁

› Ask Codex to do anything
Expand Down
3 changes: 2 additions & 1 deletion codex-rs/tui/src/app_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,12 @@ pub(crate) enum KeymapEditIntent {
ReplaceOne { old_key: String },
}

/// Number of key strokes recorded by one `/keymap` capture.
/// Kind of shortcut recorded by one `/keymap` capture.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(crate) enum KeymapCaptureMode {
SingleKey,
Chord,
LeaderChord,
}

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
7 changes: 5 additions & 2 deletions codex-rs/tui/src/bottom_pane/async_questions/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ impl AsyncQuestions {
}
}

pub(crate) fn resolve_answers(&mut self, question_ids: &[String]) {
/// Return whether resolving these answers changed the expanded question's input target.
pub(crate) fn resolve_answers(&mut self, question_ids: &[String]) -> bool {
// History can arrive before live questions or before restoring local drafts.
self.state.answered_ids.extend(question_ids.iter().cloned());
// Older desktop replies identify the whole source message instead of one question.
Expand All @@ -158,9 +159,10 @@ impl AsyncQuestions {
|| question_ids.contains(&question.message_id)
};
if !self.state.pending.iter().any(answered) {
return;
return false;
}
let current_answered = self.current_answer().is_some_and(answered);
let displayed_answer_changed = self.expanded && current_answered;
if current_answered {
self.composer.flush_pending_input();
}
Expand All @@ -183,6 +185,7 @@ impl AsyncQuestions {
self.restore_current_draft();
self.composer.reset_vim_mode();
}
displayed_answer_changed
}

pub(crate) fn accept_answer(&mut self) {
Expand Down
10 changes: 10 additions & 0 deletions codex-rs/tui/src/bottom_pane/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//! [`BottomPaneView`]s (popups/modals) that temporarily replace the composer for focused
//! interactions like selection lists. Centered views retain earlier views as a backdrop,
//! while input remains routed exclusively to the top of the stack.
//! Modal insertion, replacement, and dismissal invalidate pending key chords, including when a
//! deferred prompt appears or an approval queue advances without changing keymap contexts.
//!
//! Input routing is layered: `BottomPane` decides which local surface receives a key (view vs
//! composer), while higher-level intent such as "interrupt" or "quit" is decided by the parent
Expand Down Expand Up @@ -288,6 +290,7 @@ pub(crate) struct BottomPane {

/// Stack of views displayed instead of the composer (e.g. popups/modals).
view_stack: Vec<Box<dyn BottomPaneView>>,
pub(crate) key_chord_reset_requested: bool,
warnings_view: Option<warnings_view::WarningsView>,
/// A keep press can close the viewer; its remaining repeats must not edit the draft.
pub(crate) suppress_warning_keep_repeat: bool,
Expand Down Expand Up @@ -376,6 +379,7 @@ impl BottomPane {
Self {
composer,
view_stack: Vec::new(),
key_chord_reset_requested: false,
warnings_view: None,
suppress_warning_keep_repeat: false,
questions: None,
Expand Down Expand Up @@ -715,6 +719,7 @@ impl BottomPane {
}

fn push_view(&mut self, view: Box<dyn BottomPaneView>) {
self.key_chord_reset_requested = true;
self.view_stack.push(view);
self.schedule_active_view_frame();
self.request_redraw();
Expand Down Expand Up @@ -744,6 +749,7 @@ impl BottomPane {
}

fn on_view_stack_depth_decreased(&mut self) {
self.key_chord_reset_requested = true;
if self.view_stack.is_empty() {
self.on_active_view_complete();
}
Expand Down Expand Up @@ -1061,6 +1067,7 @@ impl BottomPane {
self.on_active_view_complete();
}
if needs_redraw || view_complete {
self.key_chord_reset_requested = true;
self.request_redraw();
}
}
Expand Down Expand Up @@ -1510,6 +1517,7 @@ impl BottomPane {
view.dismiss_after_child_accept = self.view_stack[index].dismiss_after_child_accept();
self.view_stack[index] = Box::new(view);
if replaces_active_view {
self.key_chord_reset_requested = true;
self.schedule_active_view_frame();
}
self.request_redraw();
Expand Down Expand Up @@ -1618,6 +1626,7 @@ impl BottomPane {
return false;
}

self.key_chord_reset_requested = true;
self.view_stack.pop();
self.request_redraw();
true
Expand All @@ -1636,6 +1645,7 @@ impl BottomPane {
let removed_active_view = index + 1 == self.view_stack.len();
self.view_stack.remove(index);
if removed_active_view {
self.key_chord_reset_requested = true;
self.schedule_active_view_frame();
}
self.request_redraw();
Expand Down
6 changes: 3 additions & 3 deletions codex-rs/tui/src/bottom_pane/voice_strip_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@ fn active_dashboard_preserves_live_colors_controls_and_width() {
assert!(actual.starts_with(" voice "));
assert!(actual.lines().nth(1).unwrap().starts_with(" mic "));
insta::assert_snapshot!(actual, @"
voice ● listening ⌃x mute /voice stop
voice ● listening f9 mute /voice stop
mic ▆▅▄▃▂▁ codex ▁▃▄▅▆█
");
assert_eq!(buffer[(7, 0)].fg, Color::Red);
assert_eq!(buffer[(7, 1)].fg, Color::Cyan);
assert_eq!(buffer[(22, 1)].fg, Color::Magenta);
assert!(actual.contains("/voice stop"));
let (compact, buffer) = rows(&strip, /*width*/ 37);
assert!(compact.contains("⌃x mute") && compact.contains("/voice stop"));
assert!(compact.contains("f9 mute") && compact.contains("/voice stop"));
assert_eq!(buffer[(36, 0)].symbol(), " ");
let (narrow, buffer) = rows(&strip, /*width*/ 22);
assert!(narrow.contains("/voice stop"));
Expand All @@ -89,7 +89,7 @@ fn connecting_and_muted_indicators_follow_actual_capture() {
strip.state.animations = false;
let (connecting, buffer) = rows(&strip, /*width*/ 45);
assert!(connecting.contains("voice ◌ connecting"));
assert!(!connecting.contains("⌃x mute"));
assert!(!connecting.contains("f9 mute"));
assert_ne!(buffer[(7, 0)].fg, Color::Red);
strip.state.microphone_live = true;
let (_, buffer) = rows(&strip, /*width*/ 45);
Expand Down
4 changes: 4 additions & 0 deletions codex-rs/tui/src/chatwidget/interaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ impl ChatWidget {
self.bottom_pane.keymap_contexts()
}

pub(crate) fn take_key_chord_reset(&mut self) -> bool {
std::mem::take(&mut self.bottom_pane.key_chord_reset_requested)
}

pub(crate) fn handle_key_event(&mut self, key_event: KeyEvent) -> KeyEventAction {
if self.handle_startup_submission_key(key_event) {
return KeyEventAction::None;
Expand Down
12 changes: 6 additions & 6 deletions codex-rs/tui/src/chatwidget/realtime/recording_controls_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ async fn voice_composer_preserves_normal_colors_across_microphone_states() {
.join("\n");
insta::assert_snapshot!(rows, @"
0:
1: voice ● listening ⌃x mute /voice stop
1: voice ● listening f9 mute /voice stop
2: mic ▁▁▁▁▁▁ codex ▁▁▁▁▁▁
3:
4: › typed
Expand Down Expand Up @@ -357,7 +357,7 @@ async fn narrow_voice_footer_keeps_the_stop_control_before_meters() {

let footer = render_bottom_popup(&chat, /*width*/ 46);
assert!(footer.contains("voice ● speaking"));
assert!(footer.contains("⌃x mute"));
assert!(footer.contains("f9 mute"));
assert!(footer.contains("/voice stop"));
chat.realtime_conversation.speaker_active_until = None;
chat.realtime_conversation.speaker_level = 1;
Expand All @@ -375,7 +375,7 @@ async fn narrow_voice_footer_keeps_the_stop_control_before_meters() {
assert_eq!(chat.realtime_conversation.speaker_active_until, None);
let interrupted = render_bottom_popup(&chat, /*width*/ 45);
assert!(interrupted.contains("voice ● heard"));
assert!(interrupted.contains("⌃x mute"));
assert!(interrupted.contains("f9 mute"));
assert!(interrupted.contains("/voice stop"));
chat.realtime_conversation.interruption_acknowledged_until =
Some(std::time::Instant::now() - super::super::INTERRUPTION_ACKNOWLEDGMENT);
Expand Down Expand Up @@ -605,15 +605,15 @@ async fn clipped_voice_composer_keeps_the_draft_and_cursor_visible() {

insta::assert_snapshot!(layouts.join("\n\n"), @"
5 rows:
voice ● listening ⌃x mute /voice stop
voice ● listening f9 mute /voice stop
› typed

6 rows:
voice ● listening ⌃x mute /voice stop
voice ● listening f9 mute /voice stop
› typed

8 rows:
voice ● listening ⌃x mute /voice stop
voice ● listening f9 mute /voice stop
› typed
");
}
Expand Down
Loading
Loading