Fuzzy match-and-rank function in Rust #147

Closed
opened 2026-09-03 13:26:50 +01:00 by naps62-yolo · 1 comment
Collaborator

Implement the match-and-rank function from docs/COMMAND-BAR.md in Rust, in
crates/maestro-tui/, as a pure function over candidates — no rendering, no
app state.

It takes a query and a list of candidates (carrying the text fields the doc
says are matched: name, directory, command, tool) and returns the matching
subset in ranked order, along with the matched character ranges so the overlay
can highlight them.

Test it against the fixture table in docs/COMMAND-BAR.md — the same cases the
TypeScript matcher is tested against.

Note the module name: palette.rs is already the colour palette. Do not put
this there.

Non-goals: no overlay, no action wiring, no command or directory candidates —
this issue is the scoring function and its tests.

Depends on: #144

Implement the match-and-rank function from `docs/COMMAND-BAR.md` in Rust, in `crates/maestro-tui/`, as a pure function over candidates — no rendering, no app state. It takes a query and a list of candidates (carrying the text fields the doc says are matched: name, directory, command, tool) and returns the matching subset in ranked order, along with the matched character ranges so the overlay can highlight them. Test it against the fixture table in `docs/COMMAND-BAR.md` — the same cases the TypeScript matcher is tested against. Note the module name: `palette.rs` is already the colour palette. Do not put this there. Non-goals: no overlay, no action wiring, no command or directory candidates — this issue is the scoring function and its tests. Depends on: #144
naps62-yolo added this to the Command bar milestone 2026-09-03 13:26:50 +01:00
naps62-yolo added the area/tuidifficulty/mediumtype/feat labels 2026-09-03 13:26:50 +01:00
naps62-yolo added a new dependency 2026-09-03 13:26:52 +01:00
Author
Collaborator

Merged into blitz/command-bar. Rust suite re-run on the integration branch:
751 passed, 0 failed.

I checked the fixture scores against the doc and against web/src/matcher.ts
rather than only against the run. All twelve agree with both, so the two
clients now rank identically — which was the whole point of specifying the
algorithm before either was written.

The three details that would have gone unnoticed until later are all right:
sort_by rather than sort_unstable_by, so input order survives as the last
tie-break; Vec<char> positions rather than byte offsets, which only shows up
on a non-ASCII session name; and best_embedding is the dynamic program, so
F5 passes for the right reason.

Merged into `blitz/command-bar`. Rust suite re-run on the integration branch: 751 passed, 0 failed. I checked the fixture scores against the doc and against `web/src/matcher.ts` rather than only against the run. All twelve agree with both, so the two clients now rank identically — which was the whole point of specifying the algorithm before either was written. The three details that would have gone unnoticed until later are all right: `sort_by` rather than `sort_unstable_by`, so input order survives as the last tie-break; `Vec<char>` positions rather than byte offsets, which only shows up on a non-ASCII session name; and `best_embedding` is the dynamic program, so F5 passes for the right reason.
This repo is archived. You cannot comment on issues.
1 Participants
Due Date
No due date set.
Reference: naps62/maestro#147