Implementation:1ay1 Agentty Fuzzy Matcher
| Knowledge Sources | |
|---|---|
| Domains | UI, Search |
| Last Updated | 2026-10-28 12:00 GMT |
Overview
Scored subsequence matcher shared by every incremental picker, ranking candidates by how well the query matches and returning matched offsets for highlighting.
Description
The agentty::fuzzy module is the one scored subsequence matcher shared by every incremental picker (command palette, @-files, #-symbols, model/provider picker). It ranks a candidate by HOW WELL the query matches it: leading prefix > word-boundary/acronym > consecutive run > scattered subsequence; exact wins. Returns the matched character offsets so the view can highlight them.
Scoring: +16 per matched char, +18 for consecutive runs, +30 for word-boundary matches, +25 for leading prefix, +40 for exact match, minus a mild gap penalty per skipped char. Greedy left-to-right — suboptimal for pathological cases but fast and good enough for live per-keystroke filtering.
Usage
Import this when you need to: score a candidate against a query for any incremental picker, check if a query fuzzy-matches a candidate, or get match positions for highlighting.
Code Reference
Source Location
- Repository: 1ay1_Agentty
- File: include/agentty/runtime/fuzzy.hpp
- Lines: 1-82
Signature
namespace agentty::fuzzy {
struct Match {
int score = INT_MIN; // higher = better; INT_MIN = no match
std::vector<int> positions; // matched byte offsets
[[nodiscard]] bool matched() const noexcept;
};
[[nodiscard]] inline bool is_word_boundary(std::string_view s, std::size_t i) noexcept;
[[nodiscard]] inline Match score(std::string_view hay, std::string_view needle);
[[nodiscard]] inline bool matches(std::string_view hay, std::string_view needle);
}
Import
#include "agentty/runtime/fuzzy.hpp"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| hay | std::string_view | Yes | The candidate string (haystack) |
| needle | std::string_view | Yes | The query (need NOT be pre-lowercased) |
Outputs
| Name | Type | Description |
|---|---|---|
| Match.score | int | Ranking score (INT_MIN = no match); higher = better |
| Match.positions | std::vector<int> | Matched byte offsets into the candidate |
Usage Examples
Score and Highlight
#include "agentty/runtime/fuzzy.hpp"
auto m = agentty::fuzzy::score("gpt-sonnet-4", "sp4");
if (m.matched()) {
// m.score — how well it matched
// m.positions — byte offsets for fzf-style highlighting
for (int pos : m.positions) {
// highlight candidate[pos]
}
}
Boolean Check
if (agentty::fuzzy::matches("claude-opus-4-8", "op48")) {
// "op48" is a subsequence of "claude-opus-4-8"
}