Skip to content

Commit 80791c2

Browse files
committed
tui: prevent scoped npm package tokens from triggering @ file search
Ignore @-prefixed tokens that contain a second @ so scoped package strings like @kaeawc/auto-mobile@latest are treated as plain text. Add a regression test that verifies this prompt submits on Enter and does not activate the file-search popup.
1 parent 999576f commit 80791c2

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

codex-rs/tui/src/bottom_pane/chat_composer.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,8 +1847,12 @@ impl ChatComposer {
18471847
let left_match = token_left.filter(|t| t.starts_with(prefix));
18481848
let right_match = token_right.filter(|t| t.starts_with(prefix));
18491849

1850-
let left_prefixed = left_match.map(|t| t[prefix.len_utf8()..].to_string());
1851-
let right_prefixed = right_match.map(|t| t[prefix.len_utf8()..].to_string());
1850+
let left_prefixed = left_match
1851+
.map(|t| t[prefix.len_utf8()..].to_string())
1852+
.filter(|value| !value.contains(prefix));
1853+
let right_prefixed = right_match
1854+
.map(|t| t[prefix.len_utf8()..].to_string())
1855+
.filter(|value| !value.contains(prefix));
18521856

18531857
if at_whitespace {
18541858
if right_prefixed.is_some() {
@@ -4826,6 +4830,39 @@ mod tests {
48264830
}
48274831
}
48284832

4833+
#[test]
4834+
fn enter_submits_prompt_ending_with_scoped_npm_package() {
4835+
use crossterm::event::KeyCode;
4836+
use crossterm::event::KeyEvent;
4837+
use crossterm::event::KeyModifiers;
4838+
4839+
let (tx, _rx) = unbounded_channel::<AppEvent>();
4840+
let sender = AppEventSender::new(tx);
4841+
let mut composer = ChatComposer::new(
4842+
true,
4843+
sender,
4844+
false,
4845+
"Ask Codex to do anything".to_string(),
4846+
false,
4847+
);
4848+
composer.set_steer_enabled(true);
4849+
4850+
let prompt = "npx -y @kaeawc/auto-mobile@latest";
4851+
composer.insert_str(prompt);
4852+
assert!(
4853+
!composer.popup_active(),
4854+
"scoped npm package should not trigger @ file search popup"
4855+
);
4856+
4857+
let (result, _needs_redraw) =
4858+
composer.handle_key_event(KeyEvent::new(KeyCode::Enter, KeyModifiers::NONE));
4859+
4860+
match result {
4861+
InputResult::Submitted { text, .. } => assert_eq!(text, prompt),
4862+
_ => panic!("expected Submitted"),
4863+
}
4864+
}
4865+
48294866
/// Behavior: if the ASCII path has a pending first char (flicker suppression) and a non-ASCII
48304867
/// char arrives next, the pending ASCII char should still be preserved and the overall input
48314868
/// should submit normally (i.e. we should not misclassify this as a paste burst).

0 commit comments

Comments
 (0)