feat: Add btw alias for side slash command (#23592)

This commit is contained in:
anp-oai
2026-05-20 08:49:35 -07:00
committed by GitHub
Unverified
parent e9f59e30d9
commit f198ca115b
7 changed files with 279 additions and 16 deletions
+18 -12
View File
@@ -30,8 +30,6 @@ struct PreparedSlashCommandArgs {
}
const SIDE_STARTING_CONTEXT_LABEL: &str = "Side starting...";
const SIDE_REVIEW_UNAVAILABLE_MESSAGE: &str =
"'/side' is unavailable while code review is running.";
const SIDE_SLASH_COMMAND_UNAVAILABLE_HINT: &str =
"Press Ctrl+C to return to the main thread first.";
const GOAL_USAGE: &str = "Usage: /goal <objective>";
@@ -114,9 +112,12 @@ impl ChatWidget {
});
}
fn request_empty_side_conversation(&mut self) {
fn request_empty_side_conversation(&mut self, cmd: SlashCommand) {
let Some(parent_thread_id) = self.thread_id else {
self.add_error_message("'/side' is unavailable before the session starts.".to_string());
let command = cmd.command();
self.add_error_message(format!(
"'/{command}' is unavailable before the session starts."
));
return;
};
@@ -239,8 +240,8 @@ impl ChatWidget {
);
}
}
SlashCommand::Side => {
self.request_empty_side_conversation();
SlashCommand::Side | SlashCommand::Btw => {
self.request_empty_side_conversation(cmd);
}
SlashCommand::Agent | SlashCommand::MultiAgents => {
self.app_event_tx.send(AppEvent::OpenAgentPicker);
@@ -745,11 +746,12 @@ impl ChatWidget {
self.bottom_pane.drain_pending_submission_state();
}
}
SlashCommand::Side if !trimmed.is_empty() => {
SlashCommand::Side | SlashCommand::Btw if !trimmed.is_empty() => {
let Some(parent_thread_id) = self.thread_id else {
self.add_error_message(
"'/side' is unavailable before the session starts.".to_string(),
);
let command = cmd.command();
self.add_error_message(format!(
"'/{command}' is unavailable before the session starts."
));
return;
};
let user_message = self.prepared_inline_user_message(
@@ -957,6 +959,7 @@ impl ChatWidget {
| SlashCommand::Plan
| SlashCommand::Goal
| SlashCommand::Side
| SlashCommand::Btw
| SlashCommand::Keymap
| SlashCommand::Agent
| SlashCommand::MultiAgents
@@ -1017,11 +1020,14 @@ impl ChatWidget {
}
fn ensure_side_command_allowed_outside_review(&mut self, cmd: SlashCommand) -> bool {
if cmd != SlashCommand::Side || !self.review.is_review_mode {
if !matches!(cmd, SlashCommand::Side | SlashCommand::Btw) || !self.review.is_review_mode {
return true;
}
self.add_error_message(SIDE_REVIEW_UNAVAILABLE_MESSAGE.to_string());
let command = cmd.command();
self.add_error_message(format!(
"'/{command}' is unavailable while code review is running."
));
self.bottom_pane.drain_pending_submission_state();
false
}
+113
View File
@@ -173,6 +173,59 @@ async fn slash_side_is_rejected_during_review_mode() {
);
}
#[tokio::test]
async fn slash_btw_is_rejected_during_review_mode() {
let (mut chat, mut rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
chat.review.is_review_mode = true;
chat.dispatch_command(SlashCommand::Btw);
let event = rx
.try_recv()
.expect("expected review-mode btw conversation error");
match event {
AppEvent::InsertHistoryCell(cell) => {
let rendered = lines_to_single_string(&cell.display_lines(/*width*/ 80));
assert!(
rendered.contains("'/btw' is unavailable while code review is running."),
"expected review-mode btw conversation error, got {rendered:?}"
);
}
other => panic!("expected InsertHistoryCell error, got {other:?}"),
}
assert!(rx.try_recv().is_err(), "expected no follow-up events");
assert!(
op_rx.try_recv().is_err(),
"expected no side conversation op"
);
}
#[tokio::test]
async fn slash_btw_is_rejected_before_the_session_starts() {
let (mut chat, mut rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
chat.dispatch_command(SlashCommand::Btw);
let event = rx
.try_recv()
.expect("expected pre-session btw conversation error");
match event {
AppEvent::InsertHistoryCell(cell) => {
let rendered = lines_to_single_string(&cell.display_lines(/*width*/ 80));
assert!(
rendered.contains("'/btw' is unavailable before the session starts."),
"expected pre-session btw conversation error, got {rendered:?}"
);
}
other => panic!("expected InsertHistoryCell error, got {other:?}"),
}
assert!(rx.try_recv().is_err(), "expected no follow-up events");
assert!(
op_rx.try_recv().is_err(),
"expected no side conversation op"
);
}
#[tokio::test]
async fn submit_user_message_as_plain_user_turn_does_not_run_shell_commands() {
let (mut chat, _rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
@@ -219,6 +272,31 @@ async fn slash_side_without_args_starts_empty_side_conversation() {
assert!(chat.input_queue.queued_user_messages.is_empty());
}
#[tokio::test]
async fn slash_btw_without_args_starts_empty_side_conversation() {
let (mut chat, mut rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
let parent_thread_id = ThreadId::new();
chat.thread_id = Some(parent_thread_id);
chat.on_task_started();
chat.bottom_pane
.set_composer_text("/btw".to_string(), Vec::new(), Vec::new());
chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
assert_matches!(
rx.try_recv(),
Ok(AppEvent::StartSide {
parent_thread_id: emitted_parent_thread_id,
user_message: None,
}) if emitted_parent_thread_id == parent_thread_id
);
assert!(
op_rx.try_recv().is_err(),
"bare /btw should not submit an op on the parent thread"
);
assert!(chat.input_queue.queued_user_messages.is_empty());
}
#[tokio::test]
async fn slash_side_requests_forked_side_question_while_task_running() {
let (mut chat, mut rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
@@ -268,6 +346,41 @@ async fn slash_side_requests_forked_side_question_while_task_running() {
);
}
#[tokio::test]
async fn slash_btw_requests_forked_side_question_while_task_running() {
let (mut chat, mut rx, mut op_rx) = make_chatwidget_manual(/*model_override*/ None).await;
let parent_thread_id = ThreadId::new();
chat.thread_id = Some(parent_thread_id);
chat.on_task_started();
chat.bottom_pane.set_composer_text(
"/btw explore the codebase".to_string(),
Vec::new(),
Vec::new(),
);
chat.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
assert_matches!(
rx.try_recv(),
Ok(AppEvent::StartSide {
parent_thread_id: emitted_parent_thread_id,
user_message: Some(user_message),
}) if emitted_parent_thread_id == parent_thread_id
&& user_message
== UserMessage {
text: "explore the codebase".to_string(),
local_images: Vec::new(),
remote_image_urls: Vec::new(),
text_elements: Vec::new(),
mention_bindings: Vec::new(),
}
);
assert!(
op_rx.try_recv().is_err(),
"expected no op on the parent thread"
);
}
#[tokio::test]
async fn side_context_label_preserves_status_line_snapshot() {
let (mut chat, _rx, _op_rx) = make_chatwidget_manual(/*model_override*/ None).await;