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 crates/coding-agent/src/agent/slash_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub fn builtin_slash_commands() -> Vec<BuiltinSlashCommand> {
vec![
builtin("settings", "Open settings menu"),
builtin_with_args("model", "Select model"),
builtin("thinking", "Select thinking level"),
builtin("scoped-models", "Enable models for Ctrl+P cycling"),
builtin("export", "Export session (JSONL)"),
builtin("import", "Import session JSONL"),
Expand Down Expand Up @@ -306,6 +307,8 @@ pub enum SlashDispatch {
Aside {
question: String,
},
/// Open the thinking level picker (`/thinking`).
Thinking,
Unimplemented(String),
}

Expand Down Expand Up @@ -618,6 +621,7 @@ pub fn slash_palette_submit_on_enter(command_name: &str) -> bool {
command_name,
"model"
| "scoped-models"
| "thinking"
| "tree"
| "resume"
| "session"
Expand Down Expand Up @@ -653,6 +657,7 @@ fn builtin_dispatch(name: &str, args: String) -> Option<SlashDispatch> {
"confetti" | "conffety" | "confetty" => Some(SlashDispatch::Confetti { args }),
"reload" => Some(SlashDispatch::Reload),
"model" => Some(SlashDispatch::OverlayNeeded(OverlayCommand::Model { filter: args })),
"thinking" | "think" => Some(SlashDispatch::Thinking),
"scoped-models" | "scoped_models" | "scopedmodels" => {
Some(SlashDispatch::OverlayNeeded(OverlayCommand::ScopedModels))
}
Expand Down Expand Up @@ -974,6 +979,14 @@ mod tests {
dispatch_slash_command("/resume abc123", None, None, None),
Some(SlashDispatch::Resume { args: "abc123".into() })
);
assert_eq!(
dispatch_slash_command("/thinking", None, None, None),
Some(SlashDispatch::Thinking)
);
assert_eq!(
dispatch_slash_command("/think", None, None, None),
Some(SlashDispatch::Thinking)
);
assert_eq!(
dispatch_slash_command("/workers", None, None, None),
Some(SlashDispatch::Workers)
Expand Down
2 changes: 2 additions & 0 deletions crates/coding-agent/src/agent/slash_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Keyboard shortcuts
Esc Cancel / close dialog
Tab Complete slash / cycle agent mode
Ctrl+P Cycle scoped models
Ctrl+. Cycle thinking level
Ctrl+S Toggle native text-select mode
Shift+↑/↓ Scroll transcript
PageUp / PageDown Scroll transcript (faster)
Expand All @@ -33,6 +34,7 @@ Keyboard shortcuts
/session Current session info
/tools Active tools
/system-prompt Compiled system prompt
/thinking Select thinking level
";

pub fn changelog_text() -> String {
Expand Down
2 changes: 1 addition & 1 deletion crates/coding-agent/src/tui/chrome/status_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const STATUS_TICK_MS: u64 = 80;
const TIPS: &[&str] = &[
"Tab toggles prompt / transcript focus",
"Shift+Tab cycles agent mode (Build · Plan · Ask · Brave)",
"Ctrl+. cycles thinking level",
"Ctrl+. cycles thinking level · /thinking picks one",
"Ctrl+L opens the model picker · Ctrl+P cycles scoped models",
"Shift+↑↓ scrolls the transcript",
"Esc returns to the prompt · type while reading to jump back",
Expand Down
2 changes: 2 additions & 0 deletions crates/coding-agent/src/tui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ mod subagent_display;
pub(crate) mod subagent_output_dialog;
mod system_prompt_dialog;
mod theme;
mod thinking_selector;
mod thinking_selector_bar;
mod tool_approval;
pub(crate) mod tool_params;
pub(crate) mod transcript;
Expand Down
9 changes: 9 additions & 0 deletions crates/coding-agent/src/tui/model_selector_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ use crate::tui::chrome::ChromeStats;
use crate::tui::focus::ShellFocus;
use crate::tui::labels::{model_display_label, model_footer_label};
use crate::tui::model_selector::{ModelCatalogOptions, ModelSelectorFocus, PendingModelSelector};
use crate::types::ThinkingLevel;

/// Re-compute of [`ThinkingLevel::cycle_for_model`] from `provider` + `model_id`
/// (keeps `thinking_selector.rs` decoupled from model catalog internals).
pub fn thinking_levels_for_model(provider: &str, model_id: &str) -> Vec<ThinkingLevel> {
get_builtin_model(provider, model_id)
.map(|model| ThinkingLevel::cycle_for_model(&model))
.unwrap_or_else(|| vec![ThinkingLevel::Off])
}

/// Arguments for [`open_model_selector`].
pub struct OpenModelSelectorArgs<'a> {
Expand Down
2 changes: 2 additions & 0 deletions crates/coding-agent/src/tui/shell/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ pub(crate) struct ShellCtx {
pub(crate) pending_rename: Ref<Option<PendingRenameDialog>>,
pub(crate) pending_item_selector: Ref<Option<crate::tui::item_selector::PendingItemSelector>>,
pub(crate) item_selector_selected: State<usize>,
pub(crate) pending_thinking_selector: Ref<Option<crate::tui::thinking_selector::PendingThinkingSelector>>,
pub(crate) thinking_selector_selected: State<usize>,
pub(crate) pending_scoped_models: Ref<Option<PendingScopedModels>>,
pub(crate) pending_subagent_output: Ref<Option<PendingSubagentOutputDialog>>,
pub(crate) pending_system_prompt: Ref<Option<PendingSystemPromptDialog>>,
Expand Down
144 changes: 142 additions & 2 deletions crates/coding-agent/src/tui/shell/keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ pub(crate) fn handle_shell_key(ctx: ShellCtx, event: TerminalEvent) {
mut pending_rename,
mut pending_item_selector,
mut item_selector_selected,
mut pending_thinking_selector,
mut thinking_selector_selected,
mut pending_scoped_models,
mut pending_system_prompt,
mut pending_aside,
Expand Down Expand Up @@ -664,6 +666,7 @@ pub(crate) fn handle_shell_key(ctx: ShellCtx, event: TerminalEvent) {
|| pending_memory_flush.read().is_some()
|| *pending_feedback.read()
|| pending_item_selector.read().is_some()
|| pending_thinking_selector.read().is_some()
|| aside_open;
if modifiers.contains(KeyModifiers::ALT)
&& !modifiers.intersects(KeyModifiers::CONTROL | KeyModifiers::META)
Expand Down Expand Up @@ -776,6 +779,7 @@ pub(crate) fn handle_shell_key(ctx: ShellCtx, event: TerminalEvent) {
let model_selector_open = pending_model_selector.read().is_some();
let scoped_models_open = pending_scoped_models.read().is_some();
let item_selector_open = pending_item_selector.read().is_some();
let thinking_selector_open = pending_thinking_selector.read().is_some();
let provider_connect_open = pending_provider_connect.read().is_some();
let mcp_auth_open = pending_mcp_auth.read().is_some();
let provider_disconnect_open = pending_provider_disconnect.read().is_some();
Expand All @@ -790,6 +794,7 @@ pub(crate) fn handle_shell_key(ctx: ShellCtx, event: TerminalEvent) {
|| model_selector_open
|| scoped_models_open
|| item_selector_open
|| thinking_selector_open
|| system_prompt_open
|| rename_open
|| confetti_open
Expand All @@ -810,6 +815,8 @@ pub(crate) fn handle_shell_key(ctx: ShellCtx, event: TerminalEvent) {
&& pending_user_question.read().is_none()
&& !model_selector_open
&& !scoped_models_open
&& !item_selector_open
&& !thinking_selector_open
&& !system_prompt_open
{
let len = prompt_queue.read().len();
Expand Down Expand Up @@ -1280,6 +1287,83 @@ pub(crate) fn handle_shell_key(ctx: ShellCtx, event: TerminalEvent) {
}
}

// ── Thinking level selector (/thinking) ────────────────────────
if thinking_selector_open
&& pending_user_question.read().is_none()
&& !system_prompt_open
&& !confetti_open
&& !model_selector_open
&& !scoped_models_open
&& !rename_open
{
if modifiers.is_empty() && code == KeyCode::Esc {
close_thinking_selector(
&mut pending_thinking_selector,
&mut draft,
&mut live_draft,
&mut shell_focus,
true,
);
force_editor_clear.set(true);
return;
}

if let Some(delta) = thinking_selector_list_nav_delta(modifiers, code) {
if let Some(pending) = pending_thinking_selector.write().as_mut() {
pending.move_delta(delta);
thinking_selector_selected.set(pending.selected);
}
return;
}

if thinking_selector_confirm_on_enter(modifiers, code) {
let Some(level) = pending_thinking_selector
.read()
.as_ref()
.and_then(|p| p.selected_level())
else {
return;
};
close_thinking_selector(
&mut pending_thinking_selector,
&mut draft,
&mut live_draft,
&mut shell_focus,
false,
);
force_editor_clear.set(true);
// Clamp to the active model's catalog map (same guard as Ctrl+. / footer):
// unsupported picks (e.g. xhigh on xAI Grok 4.5) collapse to a supported
// level instead of reaching the provider API.
let clamped = if let Some(session) = agent_session.as_ref() {
level.clamp_for_provider_model(&session.model_provider(), &session.model_id())
} else {
level
};
thinking_level.set(clamped);
if let Some(session) = agent_session.as_ref() {
let session = Arc::clone(session);
tokio::spawn(async move {
if let Err(err) = session.set_thinking_level(clamped).await {
log::warn!("failed to set thinking level: {err}");
}
});
}
let expire_tx = ephemeral_expire.read().tx.clone();
show_ephemeral_banner(
&mut ephemeral_banner,
&mut ephemeral_banner_generation,
&expire_tx,
thinking_level_banner(clamped),
);
return;
}

if !shell_global_shortcut(modifiers, code) {
return;
}
}

if model_selector_open
&& pending_user_question.read().is_none()
&& !system_prompt_open
Expand Down Expand Up @@ -1471,7 +1555,7 @@ pub(crate) fn handle_shell_key(ctx: ShellCtx, event: TerminalEvent) {
model_set_notice_text(&label),
);
if let Some(session) = agent {
spawn_runtime_model_switch(session, value, thinking_level.get());
spawn_runtime_model_switch(session, value.clone(), thinking_level.get());
}
}
Err(err) => {
Expand All @@ -1482,10 +1566,36 @@ pub(crate) fn handle_shell_key(ctx: ShellCtx, event: TerminalEvent) {
&mut prompt_history,
TranscriptMessage::text(format!("{err}"), TranscriptStyle::Meta),
);
return;
}
}

// Model applied: close the picker, then open the thinking level
// picker filtered to the newly selected model's catalog (same
// multi-step dialog pattern as the provider-connect flow).
close_model_selector(&mut pending_model_selector, &mut draft, &mut live_draft, &mut shell_focus);
let pending = {
let (provider, model_id) = match crate::agent::parse_model_value(&value) {
Ok((p, m)) => (p, m),
Err(_) => (String::new(), String::new()),
};
crate::tui::thinking_selector::PendingThinkingSelector::open_for_model(
&provider,
&model_id,
thinking_level.get(),
)
};
open_thinking_selector(OpenThinkingSelectorArgs {
pending: &mut pending_thinking_selector,
draft: &mut draft,
live_draft: &mut live_draft,
shell_focus: &mut shell_focus,
selected_index: Some(&mut thinking_selector_selected),
pending_selector: pending,
});
force_editor_clear.set(true);
suppress_enter_newline.set(true);
}
close_model_selector(&mut pending_model_selector, &mut draft, &mut live_draft, &mut shell_focus);
return;
}

Expand Down Expand Up @@ -3356,6 +3466,36 @@ pub(crate) fn handle_shell_key(ctx: ShellCtx, event: TerminalEvent) {
session_scoped: &session_scoped_items.read(),
});
}
SlashOutcome::OpenThinkingSelector => {
// `mut` + write guard: resolve the active model (session or
// footer label) and build model-catalog-limited levels.
let pending = {
let (provider, model_id) = if let Some(session) = agent_session.as_ref() {
(session.model_provider(), session.model_id())
} else {
let label = chrome_stats.read().model_label.clone();
match crate::agent::parse_model_value(&label) {
Ok((p, m)) => (p, m),
Err(_) => (String::new(), String::new()),
}
};
crate::tui::thinking_selector::PendingThinkingSelector::open_for_model(
&provider,
&model_id,
thinking_level.get(),
)
};
open_thinking_selector(OpenThinkingSelectorArgs {
pending: &mut pending_thinking_selector,
draft: &mut draft,
live_draft: &mut live_draft,
shell_focus: &mut shell_focus,
selected_index: Some(&mut thinking_selector_selected),
pending_selector: pending,
});
force_editor_clear.set(true);
suppress_enter_newline.set(true);
}
SlashOutcome::OpenSystemPromptDialog { text } => {
open_system_prompt_dialog(OpenSystemPromptDialogArgs {
pending: &mut pending_system_prompt,
Expand Down
11 changes: 10 additions & 1 deletion crates/coding-agent/src/tui/shell/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ use crate::tui::system_prompt_dialog::{
OpenSystemPromptDialogArgs, PendingSystemPromptDialog, close_system_prompt_dialog, open_system_prompt_dialog,
system_prompt_dialog_chrome,
};
use crate::tui::thinking_selector::{
OpenThinkingSelectorArgs, PendingThinkingSelector, close_thinking_selector, open_thinking_selector,
thinking_selector_confirm_on_enter, thinking_selector_list_nav_delta,
};
use crate::tui::thinking_selector_bar::ThinkingSelectorBar;
use crate::tui::tool_approval::{
FEEDBACK_DEFAULT_INDEX, PLAN_CONFIRM_DEFAULT_INDEX, PendingMemoryFlush, PendingModeChange, PendingPlanConfirmation,
PendingToolApproval, PlanChoice, TOOL_APPROVAL_DEFAULT_INDEX, choice_at_index_for, feedback_url_at_index, open_url,
Expand All @@ -144,7 +149,7 @@ use crate::tui::transcript::{
apply_transcript_retention, clear_ephemeral_banner, clear_ephemeral_banner_if_generation, clipboard_notice_banner,
expire_ephemeral_banner, file_picker_hidden_notice_text, model_set_notice_from_value, model_set_notice_text,
prompt_copy_banner, prompt_copy_failed_banner, publish_ephemeral_banner, quit_busy_banner, select_mode_off_banner,
select_mode_on_banner, theme_mode_banner, toggle_latest_collapsible_detail,
select_mode_on_banner, theme_mode_banner, thinking_level_banner, toggle_latest_collapsible_detail,
};
use crate::tui::user_question::PendingUserQuestion;
use crate::tui::user_question::{
Expand Down Expand Up @@ -516,6 +521,8 @@ pub fn MainShell(props: &mut MainShellProps, mut hooks: Hooks) -> impl Into<AnyE
let rename_value = hooks.use_state(String::new);
let pending_item_selector = hooks.use_ref(|| None::<PendingItemSelector>);
let item_selector_selected = hooks.use_state(|| 0usize);
let pending_thinking_selector = hooks.use_ref(|| None::<PendingThinkingSelector>);
let thinking_selector_selected = hooks.use_state(|| 0usize);
let pending_confetti = hooks.use_ref(|| None::<PendingConfetti>);
let pending_provider_connect = hooks.use_ref(|| None::<PendingProviderConnectDialog>);
let pending_provider_disconnect = hooks.use_ref(|| None::<PendingProviderDisconnectDialog>);
Expand Down Expand Up @@ -743,6 +750,8 @@ pub fn MainShell(props: &mut MainShellProps, mut hooks: Hooks) -> impl Into<AnyE
pending_rename,
pending_item_selector,
item_selector_selected,
pending_thinking_selector,
thinking_selector_selected,
pending_scoped_models,
pending_subagent_output,
pending_system_prompt,
Expand Down
Loading