diff --git a/packages/cli-rs/crates/tui/src/dialogs/model.rs b/packages/cli-rs/crates/tui/src/dialogs/model.rs index f459f7c3edc..a345604b9a4 100644 --- a/packages/cli-rs/crates/tui/src/dialogs/model.rs +++ b/packages/cli-rs/crates/tui/src/dialogs/model.rs @@ -256,8 +256,14 @@ fn catalog_options( option }; if !needle.is_empty() { - let matches = - fuzzy::go(needle, &rows, |row| [Some(row.title.as_str()), row.category.as_deref()], fuzzy::best_key, 0.0); + let matches = fuzzy::go_scored( + needle, + &rows, + |row| [Some(row.title.as_str()), row.category.as_deref()], + |_, score, _| score, + 0.0, + usize::MAX, + ); let mut results: Vec = matches.into_iter().map(|index| rows[index].clone()).collect(); sort_rows(&mut results, false); prioritize(&mut results, |row| &row.value, &favorite_priority); diff --git a/packages/cli-rs/crates/tui/tests/all/models.rs b/packages/cli-rs/crates/tui/tests/all/models.rs index 8dac487acb3..0c251fdc594 100644 --- a/packages/cli-rs/crates/tui/tests/all/models.rs +++ b/packages/cli-rs/crates/tui/tests/all/models.rs @@ -342,6 +342,20 @@ fn a_filter_typed_before_the_limits_arrive_stays() { assert!(!screen.contains("Claude Haiku"), "the filter was lost:\n{screen}"); } +#[test] +fn a_search_with_spaces_ranks_by_its_words_across_title_and_provider() { + let h = mount(); + h.app.press("ctrl+x"); + h.app.press("m"); + h.wait_for("Search models"); + // fuzzysort's default score sums each word's best key: "Grok Code" (OpenCode) before "Claude Haiku". + h.app.type_text("o c"); + let screen = h.wait_for("Grok Code"); + let at = |name: &str| screen.find(name).unwrap_or_else(|| panic!("no {name}:\n{screen}")); + assert!(at("Grok Code") < at("Claude Haiku"), "{screen}"); + assert!(at("Claude Haiku") < at("Claude Sonnet"), "{screen}"); +} + #[test] fn the_prompt_shows_and_submits_the_model_picked_in_the_dialog() { let h = mount(); diff --git a/packages/cli-rs/parity/deviations/DLG12-free-models-detail.md b/packages/cli-rs/parity/deviations/DLG12-free-models-detail.md deleted file mode 100644 index 74cbbb1be52..00000000000 --- a/packages/cli-rs/parity/deviations/DLG12-free-models-detail.md +++ /dev/null @@ -1,18 +0,0 @@ -# DLG12: the model pickers rank multi-word searches with fuzzysort's per-key score - -## TypeScript - -`DialogConnectedModels` (`packages/tui/src/component/dialog-model.tsx:182-194`) and `DialogFreeModels` -(`component/dialog-model-free.tsx:39-43`) filter with `fuzzysort.go(needle, options, { keys })`. A search with -spaces is split into words, and each option scores by the words it matches across its keys. - -## Rust - -The pickers list the same models in the same order, with the same header description, `*` favorite marker, -actions, and `ModelDetail` line below the list. A search with spaces ranks with fuzzysort's per-key default score -instead of its space-split score. Single-word searches rank the same. - -## Reason - -U.3's `fuzzy::go` takes a score function over per-key scores only. Port the space-split scoring there, then drop -this file.